Skip to content

Completely remove extractCreativeAndSignature and factor out SignatureVerifier interface#10674

Merged
keithwrightbos merged 4 commits intoampproject:masterfrom
google:verifier-interface
Jul 31, 2017
Merged

Completely remove extractCreativeAndSignature and factor out SignatureVerifier interface#10674
keithwrightbos merged 4 commits intoampproject:masterfrom
google:verifier-interface

Conversation

@taymonbeal
Copy link
Copy Markdown
Member

This will facilitate the introduction of the new verifier in the next PR.

One of the PRs that #9040 is being split into. Related to #7618. Follow-up to #10594.

@jonkeller jonkeller self-requested a review July 27, 2017 18:20
urlBuilt: '1',
adRequestStart: '2',
adRequestEnd: '3',
extractCreativeAndSignature: '4',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should 5...9 be renumbered as 4...8?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that screw up our monitoring?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good answer to my question :) Nevermind.

*/
verify(creative, headers, lifecycleCallback) {
if (!this.isAvailable_()) {
return Promise.resolve(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think log messages here and at line 204 might be helpful in the future. Or alternatively, in the switch statement in the previous file where NO_FAULT is handled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of log messages do you want?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to https://github.com/ampproject/amphtml/pull/10674/files#diff-b139e3c4641f6d160f2832cba8be0761R666, where for KEY_NOT_FOUND and SIGNATURE_MISMATCH you do:

  user().error(
       TAG, this.element.getAttribute('type'),
       'Signature verification failed');

...but for NO_FAULT, there is no user().error(...). My concern is that we don't want a silent failure if there is a network issue. So maybe in the NO_FAULT case of that switch include the same error message. Or you could log "Signature verification failed because signature verifier is unavailable" either in the switch or here in verify().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those error calls were copied over from this code's previous home in amp-a4a.js. At some point they need to be cleaned up.

Do user().error logs go to Stackdriver, or is this just for the Dev Tools? The Dev Tools will already log a failed network request. I'm not sure it makes sense to log connectivity failures to StackDriver. If we're worried about CORS, maybe it would make sense to downsample them or something?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - since they were just copied code and not new to this PR, I'm fine to wait until later to clean up.
I'm not 100% sure of the answer to your Stackdriver question, but I think they do. I agree with your point about the Dev Tools.

// service, keyInfoPromise, can verify the signature, then the
// creative is valid AMP.
if (verified) {
return Promise.reject('noop');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/noop/redundant/ ?

// Note: the 'keyInfo &&' check here is not strictly
// necessary, because we checked that above. But
// Closure type compiler can't seem to recognize that, so
// this guarantees it to the compiler.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "keyInfo &&" could you cast to reassure Closure that it's non-null?

* @param {!Object} jwk An object which is hopefully an RSA JSON Web Key. The
* caller should verify that it is an object before calling this function.
* @return {!Promise<!PublicKeyInfoDef>}
* @private
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* the public key.
*/
verifySignature(data, signature, publicKeyInfo) {
verifySignature_(data, signature, publicKeyInfo) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @private
*/
importPublicKey(serviceName, jwk) {
importPublicKey_(signingServiceName, jwk) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keysetBody =
`{"keys":[${validCSSAmp.publicKey},${
validCSSAmp.publicKey
},${validCSSAmp.publicKey}]}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the linter won't like this indentation...but it's a test file so probably doesn't get seen by the linter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter looks at test files, but it doesn't care what you do inside template literals. clang-format is terrible at this. I'll make it less ugly.

* @param {!Headers} headers
* @param {function(string, !Object)} lifecycleCallback called for each AMP
* lifecycle event triggered during verification
* @return {!Promise<?VerificationFailure>} resolves to `null` on success, or,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would have created a VerificationFailure.NONE to indicate success as opposed to giving null special meaning but up to you...

return Promise.reject('redundant');
}
if (!keyInfo) {
return Promise.reject('Promise resolved to null key.');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this happen in practice? Should we log back to stackdriver to track occurrence?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would happen if the JSON object from the signing service could not be successfully converted into a crypto key. We do log to user().error when that happens, but at import time, not at verification time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants