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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_KEY_OPENSSL_H_ 6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_KEY_OPENSSL_H_ 7 8 #include "content/child/webcrypto/algorithm_implementation.h" 9 10 namespace content { 11 12 namespace webcrypto { 13 14 class PublicKeyNss; 15 class PrivateKeyNss; 16 17 // Base class for an RSA algorithm whose keys additionaly have a hash parameter 18 // bound to them. Provides functionality for generating, importing, and 19 // exporting keys. 20 class RsaHashedAlgorithm : public AlgorithmImplementation { 21 public: 22 // |all_public_key_usages| and |all_private_key_usages| are the set of 23 // WebCrypto key usages that are valid for created keys (public and private 24 // respectively). 25 // 26 // For instance if public keys support encryption and wrapping, and private 27 // keys support decryption and unwrapping callers should set: 28 // all_public_key_usages = UsageEncrypt | UsageWrap 29 // all_private_key_usages = UsageDecrypt | UsageUnwrap 30 // This information is used when importing or generating keys, to enforce 31 // that valid key usages are allowed. 32 RsaHashedAlgorithm(blink::WebCryptoKeyUsageMask all_public_key_usages, 33 blink::WebCryptoKeyUsageMask all_private_key_usages) 34 : all_public_key_usages_(all_public_key_usages), 35 all_private_key_usages_(all_private_key_usages) {} 36 37 // For instance "RSA-OAEP-256". 38 virtual const char* GetJwkAlgorithm( 39 const blink::WebCryptoAlgorithmId hash) const = 0; 40 41 virtual Status VerifyKeyUsagesBeforeGenerateKeyPair( 42 blink::WebCryptoKeyUsageMask combined_usage_mask, 43 blink::WebCryptoKeyUsageMask* public_usage_mask, 44 blink::WebCryptoKeyUsageMask* private_usage_mask) const OVERRIDE; 45 46 virtual Status GenerateKeyPair( 47 const blink::WebCryptoAlgorithm& algorithm, 48 bool extractable, 49 blink::WebCryptoKeyUsageMask public_usage_mask, 50 blink::WebCryptoKeyUsageMask private_usage_mask, 51 blink::WebCryptoKey* public_key, 52 blink::WebCryptoKey* private_key) const OVERRIDE; 53 54 virtual Status VerifyKeyUsagesBeforeImportKey( 55 blink::WebCryptoKeyFormat format, 56 blink::WebCryptoKeyUsageMask usage_mask) const OVERRIDE; 57 58 virtual Status ImportKeyPkcs8(const CryptoData& key_data, 59 const blink::WebCryptoAlgorithm& algorithm, 60 bool extractable, 61 blink::WebCryptoKeyUsageMask usage_mask, 62 blink::WebCryptoKey* key) const OVERRIDE; 63 64 virtual Status ImportKeySpki(const CryptoData& key_data, 65 const blink::WebCryptoAlgorithm& algorithm, 66 bool extractable, 67 blink::WebCryptoKeyUsageMask usage_mask, 68 blink::WebCryptoKey* key) const OVERRIDE; 69 70 virtual Status ImportKeyJwk(const CryptoData& key_data, 71 const blink::WebCryptoAlgorithm& algorithm, 72 bool extractable, 73 blink::WebCryptoKeyUsageMask usage_mask, 74 blink::WebCryptoKey* key) const OVERRIDE; 75 76 virtual Status ExportKeyPkcs8(const blink::WebCryptoKey& key, 77 std::vector<uint8_t>* buffer) const OVERRIDE; 78 79 virtual Status ExportKeySpki(const blink::WebCryptoKey& key, 80 std::vector<uint8_t>* buffer) const OVERRIDE; 81 82 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key, 83 std::vector<uint8_t>* buffer) const OVERRIDE; 84 85 private: 86 blink::WebCryptoKeyUsageMask all_public_key_usages_; 87 blink::WebCryptoKeyUsageMask all_private_key_usages_; 88 }; 89 90 } // namespace webcrypto 91 92 } // namespace content 93 94 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_KEY_OPENSSL_H_ 95