| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cryptohi.h> | 5 #include <cryptohi.h> |
| 6 | 6 |
| 7 #include "content/child/webcrypto/crypto_data.h" | 7 #include "content/child/webcrypto/crypto_data.h" |
| 8 #include "content/child/webcrypto/nss/key_nss.h" | 8 #include "content/child/webcrypto/nss/key_nss.h" |
| 9 #include "content/child/webcrypto/nss/rsa_key_nss.h" | 9 #include "content/child/webcrypto/nss/rsa_key_nss.h" |
| 10 #include "content/child/webcrypto/nss/util_nss.h" | 10 #include "content/child/webcrypto/nss/util_nss.h" |
| 11 #include "content/child/webcrypto/status.h" | 11 #include "content/child/webcrypto/status.h" |
| 12 #include "crypto/scoped_nss_types.h" | 12 #include "crypto/scoped_nss_types.h" |
| 13 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 13 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 namespace webcrypto { | 17 namespace webcrypto { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class RsaSsaImplementation : public RsaHashedAlgorithm { | 21 class RsaSsaImplementation : public RsaHashedAlgorithm { |
| 22 public: | 22 public: |
| 23 RsaSsaImplementation() | 23 RsaSsaImplementation() |
| 24 : RsaHashedAlgorithm(CKF_SIGN | CKF_VERIFY, | 24 : RsaHashedAlgorithm(CKF_SIGN | CKF_VERIFY, |
| 25 blink::WebCryptoKeyUsageVerify, | 25 blink::WebCryptoKeyUsageVerify, |
| 26 blink::WebCryptoKeyUsageSign) {} | 26 blink::WebCryptoKeyUsageSign) {} |
| 27 | 27 |
| 28 virtual const char* GetJwkAlgorithm( | 28 virtual const char* GetJwkAlgorithm( |
| 29 const blink::WebCryptoAlgorithmId hash) const OVERRIDE { | 29 const blink::WebCryptoAlgorithmId hash) const override { |
| 30 switch (hash) { | 30 switch (hash) { |
| 31 case blink::WebCryptoAlgorithmIdSha1: | 31 case blink::WebCryptoAlgorithmIdSha1: |
| 32 return "RS1"; | 32 return "RS1"; |
| 33 case blink::WebCryptoAlgorithmIdSha256: | 33 case blink::WebCryptoAlgorithmIdSha256: |
| 34 return "RS256"; | 34 return "RS256"; |
| 35 case blink::WebCryptoAlgorithmIdSha384: | 35 case blink::WebCryptoAlgorithmIdSha384: |
| 36 return "RS384"; | 36 return "RS384"; |
| 37 case blink::WebCryptoAlgorithmIdSha512: | 37 case blink::WebCryptoAlgorithmIdSha512: |
| 38 return "RS512"; | 38 return "RS512"; |
| 39 default: | 39 default: |
| 40 return NULL; | 40 return NULL; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm, | 44 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm, |
| 45 const blink::WebCryptoKey& key, | 45 const blink::WebCryptoKey& key, |
| 46 const CryptoData& data, | 46 const CryptoData& data, |
| 47 std::vector<uint8_t>* buffer) const OVERRIDE { | 47 std::vector<uint8_t>* buffer) const override { |
| 48 if (key.type() != blink::WebCryptoKeyTypePrivate) | 48 if (key.type() != blink::WebCryptoKeyTypePrivate) |
| 49 return Status::ErrorUnexpectedKeyType(); | 49 return Status::ErrorUnexpectedKeyType(); |
| 50 | 50 |
| 51 SECKEYPrivateKey* private_key = PrivateKeyNss::Cast(key)->key(); | 51 SECKEYPrivateKey* private_key = PrivateKeyNss::Cast(key)->key(); |
| 52 | 52 |
| 53 const blink::WebCryptoAlgorithm& hash = | 53 const blink::WebCryptoAlgorithm& hash = |
| 54 key.algorithm().rsaHashedParams()->hash(); | 54 key.algorithm().rsaHashedParams()->hash(); |
| 55 | 55 |
| 56 // Pick the NSS signing algorithm by combining RSA-SSA (RSA PKCS1) and the | 56 // Pick the NSS signing algorithm by combining RSA-SSA (RSA PKCS1) and the |
| 57 // inner hash of the input Web Crypto algorithm. | 57 // inner hash of the input Web Crypto algorithm. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 | 84 |
| 85 buffer->assign(signature_item->data, | 85 buffer->assign(signature_item->data, |
| 86 signature_item->data + signature_item->len); | 86 signature_item->data + signature_item->len); |
| 87 return Status::Success(); | 87 return Status::Success(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, | 90 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, |
| 91 const blink::WebCryptoKey& key, | 91 const blink::WebCryptoKey& key, |
| 92 const CryptoData& signature, | 92 const CryptoData& signature, |
| 93 const CryptoData& data, | 93 const CryptoData& data, |
| 94 bool* signature_match) const OVERRIDE { | 94 bool* signature_match) const override { |
| 95 if (key.type() != blink::WebCryptoKeyTypePublic) | 95 if (key.type() != blink::WebCryptoKeyTypePublic) |
| 96 return Status::ErrorUnexpectedKeyType(); | 96 return Status::ErrorUnexpectedKeyType(); |
| 97 | 97 |
| 98 SECKEYPublicKey* public_key = PublicKeyNss::Cast(key)->key(); | 98 SECKEYPublicKey* public_key = PublicKeyNss::Cast(key)->key(); |
| 99 | 99 |
| 100 const blink::WebCryptoAlgorithm& hash = | 100 const blink::WebCryptoAlgorithm& hash = |
| 101 key.algorithm().rsaHashedParams()->hash(); | 101 key.algorithm().rsaHashedParams()->hash(); |
| 102 | 102 |
| 103 const SECItem signature_item = MakeSECItemForBuffer(signature); | 103 const SECItem signature_item = MakeSECItemForBuffer(signature); |
| 104 | 104 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| 137 | 137 |
| 138 AlgorithmImplementation* CreatePlatformRsaSsaImplementation() { | 138 AlgorithmImplementation* CreatePlatformRsaSsaImplementation() { |
| 139 return new RsaSsaImplementation; | 139 return new RsaSsaImplementation; |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace webcrypto | 142 } // namespace webcrypto |
| 143 | 143 |
| 144 } // namespace content | 144 } // namespace content |
| OLD | NEW |