| 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 "content/child/webcrypto/crypto_data.h" | 5 #include "content/child/webcrypto/crypto_data.h" |
| 6 #include "content/child/webcrypto/openssl/key_openssl.h" | 6 #include "content/child/webcrypto/openssl/key_openssl.h" |
| 7 #include "content/child/webcrypto/openssl/rsa_key_openssl.h" | 7 #include "content/child/webcrypto/openssl/rsa_key_openssl.h" |
| 8 #include "content/child/webcrypto/openssl/util_openssl.h" | 8 #include "content/child/webcrypto/openssl/util_openssl.h" |
| 9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
| 10 #include "crypto/openssl_util.h" | 10 #include "crypto/openssl_util.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 return Status::Success(); | 31 return Status::Success(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 class RsaSsaImplementation : public RsaHashedAlgorithm { | 34 class RsaSsaImplementation : public RsaHashedAlgorithm { |
| 35 public: | 35 public: |
| 36 RsaSsaImplementation() | 36 RsaSsaImplementation() |
| 37 : RsaHashedAlgorithm(blink::WebCryptoKeyUsageVerify, | 37 : RsaHashedAlgorithm(blink::WebCryptoKeyUsageVerify, |
| 38 blink::WebCryptoKeyUsageSign) {} | 38 blink::WebCryptoKeyUsageSign) {} |
| 39 | 39 |
| 40 virtual const char* GetJwkAlgorithm( | 40 virtual const char* GetJwkAlgorithm( |
| 41 const blink::WebCryptoAlgorithmId hash) const OVERRIDE { | 41 const blink::WebCryptoAlgorithmId hash) const override { |
| 42 switch (hash) { | 42 switch (hash) { |
| 43 case blink::WebCryptoAlgorithmIdSha1: | 43 case blink::WebCryptoAlgorithmIdSha1: |
| 44 return "RS1"; | 44 return "RS1"; |
| 45 case blink::WebCryptoAlgorithmIdSha256: | 45 case blink::WebCryptoAlgorithmIdSha256: |
| 46 return "RS256"; | 46 return "RS256"; |
| 47 case blink::WebCryptoAlgorithmIdSha384: | 47 case blink::WebCryptoAlgorithmIdSha384: |
| 48 return "RS384"; | 48 return "RS384"; |
| 49 case blink::WebCryptoAlgorithmIdSha512: | 49 case blink::WebCryptoAlgorithmIdSha512: |
| 50 return "RS512"; | 50 return "RS512"; |
| 51 default: | 51 default: |
| 52 return NULL; | 52 return NULL; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm, | 56 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm, |
| 57 const blink::WebCryptoKey& key, | 57 const blink::WebCryptoKey& key, |
| 58 const CryptoData& data, | 58 const CryptoData& data, |
| 59 std::vector<uint8_t>* buffer) const OVERRIDE { | 59 std::vector<uint8_t>* buffer) const override { |
| 60 if (key.type() != blink::WebCryptoKeyTypePrivate) | 60 if (key.type() != blink::WebCryptoKeyTypePrivate) |
| 61 return Status::ErrorUnexpectedKeyType(); | 61 return Status::ErrorUnexpectedKeyType(); |
| 62 | 62 |
| 63 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 63 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 64 crypto::ScopedEVP_MD_CTX ctx(EVP_MD_CTX_create()); | 64 crypto::ScopedEVP_MD_CTX ctx(EVP_MD_CTX_create()); |
| 65 | 65 |
| 66 EVP_PKEY* private_key = NULL; | 66 EVP_PKEY* private_key = NULL; |
| 67 const EVP_MD* digest = NULL; | 67 const EVP_MD* digest = NULL; |
| 68 Status status = GetPKeyAndDigest(key, &private_key, &digest); | 68 Status status = GetPKeyAndDigest(key, &private_key, &digest); |
| 69 if (status.IsError()) | 69 if (status.IsError()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 85 return Status::OperationError(); | 85 return Status::OperationError(); |
| 86 | 86 |
| 87 buffer->resize(sig_len); | 87 buffer->resize(sig_len); |
| 88 return Status::Success(); | 88 return Status::Success(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, | 91 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, |
| 92 const blink::WebCryptoKey& key, | 92 const blink::WebCryptoKey& key, |
| 93 const CryptoData& signature, | 93 const CryptoData& signature, |
| 94 const CryptoData& data, | 94 const CryptoData& data, |
| 95 bool* signature_match) const OVERRIDE { | 95 bool* signature_match) const override { |
| 96 if (key.type() != blink::WebCryptoKeyTypePublic) | 96 if (key.type() != blink::WebCryptoKeyTypePublic) |
| 97 return Status::ErrorUnexpectedKeyType(); | 97 return Status::ErrorUnexpectedKeyType(); |
| 98 | 98 |
| 99 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 99 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 100 crypto::ScopedEVP_MD_CTX ctx(EVP_MD_CTX_create()); | 100 crypto::ScopedEVP_MD_CTX ctx(EVP_MD_CTX_create()); |
| 101 | 101 |
| 102 EVP_PKEY* public_key = NULL; | 102 EVP_PKEY* public_key = NULL; |
| 103 const EVP_MD* digest = NULL; | 103 const EVP_MD* digest = NULL; |
| 104 Status status = GetPKeyAndDigest(key, &public_key, &digest); | 104 Status status = GetPKeyAndDigest(key, &public_key, &digest); |
| 105 if (status.IsError()) | 105 if (status.IsError()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 | 125 |
| 126 } // namespace | 126 } // namespace |
| 127 | 127 |
| 128 AlgorithmImplementation* CreatePlatformRsaSsaImplementation() { | 128 AlgorithmImplementation* CreatePlatformRsaSsaImplementation() { |
| 129 return new RsaSsaImplementation; | 129 return new RsaSsaImplementation; |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace webcrypto | 132 } // namespace webcrypto |
| 133 | 133 |
| 134 } // namespace content | 134 } // namespace content |
| OLD | NEW |