| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebCrypto_h | 31 #ifndef WebCrypto_h |
| 32 #define WebCrypto_h | 32 #define WebCrypto_h |
| 33 | 33 |
| 34 #include "WebCommon.h" | 34 #include "WebCommon.h" |
| 35 #include "WebCryptoAlgorithm.h" | 35 #include "WebCryptoAlgorithm.h" |
| 36 #include "WebCryptoKey.h" | 36 #include "WebCryptoKey.h" |
| 37 #include "WebPrivatePtr.h" | 37 #include "WebPrivatePtr.h" |
| 38 #include "WebString.h" |
| 38 #include "WebVector.h" | 39 #include "WebVector.h" |
| 39 | 40 |
| 40 namespace WebCore { class CryptoResult; } | 41 namespace WebCore { class CryptoResult; } |
| 41 | 42 |
| 42 #if INSIDE_BLINK | 43 #if INSIDE_BLINK |
| 43 namespace WTF { template <typename T> class PassRefPtr; } | 44 namespace WTF { template <typename T> class PassRefPtr; } |
| 44 #endif | 45 #endif |
| 45 | 46 |
| 46 namespace blink { | 47 namespace blink { |
| 47 | 48 |
| 48 class WebArrayBuffer; | 49 class WebArrayBuffer; |
| 49 class WebString; | 50 class WebString; |
| 50 | 51 |
| 52 // FIXME: Remove once Blink has rolled into Chromium. |
| 53 #define WEBCRYPTO_HAS_ERROR_TYPE 1 |
| 54 |
| 55 enum WebCryptoErrorType { |
| 56 WebCryptoErrorTypeType, |
| 57 WebCryptoErrorTypeNotSupported, |
| 58 WebCryptoErrorTypeSyntax, |
| 59 WebCryptoErrorTypeInvalidState, |
| 60 WebCryptoErrorTypeInvalidAccess, |
| 61 WebCryptoErrorTypeUnknown, |
| 62 WebCryptoErrorTypeData, |
| 63 WebCryptoErrorTypeOperation, |
| 64 }; |
| 65 |
| 51 class WebCryptoResult { | 66 class WebCryptoResult { |
| 52 public: | 67 public: |
| 53 WebCryptoResult(const WebCryptoResult& o) | 68 WebCryptoResult(const WebCryptoResult& o) |
| 54 { | 69 { |
| 55 assign(o); | 70 assign(o); |
| 56 } | 71 } |
| 57 | 72 |
| 58 ~WebCryptoResult() | 73 ~WebCryptoResult() |
| 59 { | 74 { |
| 60 reset(); | 75 reset(); |
| 61 } | 76 } |
| 62 | 77 |
| 63 WebCryptoResult& operator=(const WebCryptoResult& o) | 78 WebCryptoResult& operator=(const WebCryptoResult& o) |
| 64 { | 79 { |
| 65 assign(o); | 80 assign(o); |
| 66 return *this; | 81 return *this; |
| 67 } | 82 } |
| 68 | 83 |
| 69 BLINK_PLATFORM_EXPORT void completeWithError(); | |
| 70 | |
| 71 // Note that WebString is NOT safe to pass across threads. | 84 // Note that WebString is NOT safe to pass across threads. |
| 72 // | 85 // |
| 73 // Error details are intended to be displayed to developers for debugging. | 86 // Error details are surfaced in an exception, and MUST NEVER reveal any |
| 74 // They MUST NEVER reveal any secret information such as bytes of the key | 87 // secret information such as bytes of the key or plain text. An |
| 75 // or plain text. An appropriate error would be something like: | 88 // appropriate error would be something like: |
| 76 // "iv must be 16 bytes long". | 89 // "iv must be 16 bytes long". |
| 77 BLINK_PLATFORM_EXPORT void completeWithError(const WebString&); | 90 BLINK_PLATFORM_EXPORT void completeWithError(WebCryptoErrorType, const WebSt
ring&); |
| 78 | 91 |
| 79 // Note that WebArrayBuffer is NOT safe to create from another thread. | 92 // Note that WebArrayBuffer is NOT safe to create from another thread. |
| 80 BLINK_PLATFORM_EXPORT void completeWithBuffer(const WebArrayBuffer&); | 93 BLINK_PLATFORM_EXPORT void completeWithBuffer(const WebArrayBuffer&); |
| 81 // Makes a copy of the input data given as a pointer and byte length. | 94 // Makes a copy of the input data given as a pointer and byte length. |
| 82 BLINK_PLATFORM_EXPORT void completeWithBuffer(const void*, unsigned); | 95 BLINK_PLATFORM_EXPORT void completeWithBuffer(const void*, unsigned); |
| 83 BLINK_PLATFORM_EXPORT void completeWithBoolean(bool); | 96 BLINK_PLATFORM_EXPORT void completeWithBoolean(bool); |
| 84 BLINK_PLATFORM_EXPORT void completeWithKey(const WebCryptoKey&); | 97 BLINK_PLATFORM_EXPORT void completeWithKey(const WebCryptoKey&); |
| 85 BLINK_PLATFORM_EXPORT void completeWithKeyPair(const WebCryptoKey& publicKey
, const WebCryptoKey& privateKey); | 98 BLINK_PLATFORM_EXPORT void completeWithKeyPair(const WebCryptoKey& publicKey
, const WebCryptoKey& privateKey); |
| 86 | 99 |
| 87 #if INSIDE_BLINK | 100 #if INSIDE_BLINK |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // Implementations MUST carefully sanitize algorithm inputs before using | 194 // Implementations MUST carefully sanitize algorithm inputs before using |
| 182 // them, as they come directly from the user. Few checks have been done on | 195 // them, as they come directly from the user. Few checks have been done on |
| 183 // algorithm parameters prior to passing to the embedder. | 196 // algorithm parameters prior to passing to the embedder. |
| 184 // | 197 // |
| 185 // Only the following checks can be assumed as having already passed: | 198 // Only the following checks can be assumed as having already passed: |
| 186 // | 199 // |
| 187 // * The key is extractable when calling into exportKey/wrapKey. | 200 // * The key is extractable when calling into exportKey/wrapKey. |
| 188 // * The key usages permit the operation being requested. | 201 // * The key usages permit the operation being requested. |
| 189 // * The key's algorithm matches that of the requested operation. | 202 // * The key's algorithm matches that of the requested operation. |
| 190 // | 203 // |
| 191 virtual void encrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, const u
nsigned char* data, unsigned dataSize, WebCryptoResult result) { result.complete
WithError(); } | 204 virtual void encrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, const u
nsigned char* data, unsigned dataSize, WebCryptoResult result) { result.complete
WithError(WebCryptoErrorTypeNotSupported, ""); } |
| 192 virtual void decrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, const u
nsigned char* data, unsigned dataSize, WebCryptoResult result) { result.complete
WithError(); } | 205 virtual void decrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, const u
nsigned char* data, unsigned dataSize, WebCryptoResult result) { result.complete
WithError(WebCryptoErrorTypeNotSupported, ""); } |
| 193 virtual void sign(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsi
gned char* data, unsigned dataSize, WebCryptoResult result) { result.completeWit
hError(); } | 206 virtual void sign(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsi
gned char* data, unsigned dataSize, WebCryptoResult result) { result.completeWit
hError(WebCryptoErrorTypeNotSupported, ""); } |
| 194 virtual void verifySignature(const WebCryptoAlgorithm&, const WebCryptoKey&,
const unsigned char* signature, unsigned signatureSize, const unsigned char* da
ta, unsigned dataSize, WebCryptoResult result) { result.completeWithError(); } | 207 virtual void verifySignature(const WebCryptoAlgorithm&, const WebCryptoKey&,
const unsigned char* signature, unsigned signatureSize, const unsigned char* da
ta, unsigned dataSize, WebCryptoResult result) { result.completeWithError(WebCry
ptoErrorTypeNotSupported, ""); } |
| 195 virtual void digest(const WebCryptoAlgorithm&, const unsigned char* data, un
signed dataSize, WebCryptoResult result) { result.completeWithError(); } | 208 virtual void digest(const WebCryptoAlgorithm&, const unsigned char* data, un
signed dataSize, WebCryptoResult result) { result.completeWithError(WebCryptoErr
orTypeNotSupported, ""); } |
| 196 virtual void generateKey(const WebCryptoAlgorithm&, bool extractable, WebCry
ptoKeyUsageMask, WebCryptoResult result) { result.completeWithError(); } | 209 virtual void generateKey(const WebCryptoAlgorithm&, bool extractable, WebCry
ptoKeyUsageMask, WebCryptoResult result) { result.completeWithError(WebCryptoErr
orTypeNotSupported, ""); } |
| 197 virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, uns
igned keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsag
eMask, WebCryptoResult result) { result.completeWithError(); } | 210 virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, uns
igned keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsag
eMask, WebCryptoResult result) { result.completeWithError(WebCryptoErrorTypeNotS
upported, ""); } |
| 198 virtual void exportKey(WebCryptoKeyFormat, const WebCryptoKey&, WebCryptoRes
ult result) { result.completeWithError(); } | 211 virtual void exportKey(WebCryptoKeyFormat, const WebCryptoKey&, WebCryptoRes
ult result) { result.completeWithError(WebCryptoErrorTypeNotSupported, ""); } |
| 199 virtual void wrapKey(WebCryptoKeyFormat, const WebCryptoKey& key, const WebC
ryptoKey& wrappingKey, const WebCryptoAlgorithm&, WebCryptoResult result) { resu
lt.completeWithError(); } | 212 virtual void wrapKey(WebCryptoKeyFormat, const WebCryptoKey& key, const WebC
ryptoKey& wrappingKey, const WebCryptoAlgorithm&, WebCryptoResult result) { resu
lt.completeWithError(WebCryptoErrorTypeNotSupported, ""); } |
| 200 virtual void unwrapKey(WebCryptoKeyFormat, const unsigned char* wrappedKey,
unsigned wrappedKeySize, const WebCryptoKey&, const WebCryptoAlgorithm& unwrapAl
gorithm, const WebCryptoAlgorithm& unwrappedKeyAlgorithm, bool extractable, WebC
ryptoKeyUsageMask, WebCryptoResult result) { result.completeWithError(); } | 213 virtual void unwrapKey(WebCryptoKeyFormat, const unsigned char* wrappedKey,
unsigned wrappedKeySize, const WebCryptoKey&, const WebCryptoAlgorithm& unwrapAl
gorithm, const WebCryptoAlgorithm& unwrappedKeyAlgorithm, bool extractable, WebC
ryptoKeyUsageMask, WebCryptoResult result) { result.completeWithError(WebCryptoE
rrorTypeNotSupported, ""); } |
| 201 | 214 |
| 202 // This is the exception to the "Completing the request" guarantees | 215 // This is the exception to the "Completing the request" guarantees |
| 203 // outlined above. This is useful for Blink internal crypto and is not part | 216 // outlined above. This is useful for Blink internal crypto and is not part |
| 204 // of the WebCrypto standard. createDigestor must provide the result via | 217 // of the WebCrypto standard. createDigestor must provide the result via |
| 205 // the WebCryptoDigestor object synchronously. createDigestor may return 0 | 218 // the WebCryptoDigestor object synchronously. createDigestor may return 0 |
| 206 // if it fails to create a WebCryptoDigestor. If it succeeds, the | 219 // if it fails to create a WebCryptoDigestor. If it succeeds, the |
| 207 // WebCryptoDigestor returned by createDigestor must be freed by the | 220 // WebCryptoDigestor returned by createDigestor must be freed by the |
| 208 // caller. | 221 // caller. |
| 209 virtual WebCryptoDigestor* createDigestor(WebCryptoAlgorithmId algorithmId)
{ return 0; } | 222 virtual WebCryptoDigestor* createDigestor(WebCryptoAlgorithmId algorithmId)
{ return 0; } |
| 210 | 223 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Returns true on success. | 269 // Returns true on success. |
| 257 virtual bool serializeKeyForClone(const WebCryptoKey&, WebVector<unsigned ch
ar>&) { return false; } | 270 virtual bool serializeKeyForClone(const WebCryptoKey&, WebVector<unsigned ch
ar>&) { return false; } |
| 258 | 271 |
| 259 protected: | 272 protected: |
| 260 virtual ~WebCrypto() { } | 273 virtual ~WebCrypto() { } |
| 261 }; | 274 }; |
| 262 | 275 |
| 263 } // namespace blink | 276 } // namespace blink |
| 264 | 277 |
| 265 #endif | 278 #endif |
| OLD | NEW |