OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_ENCRYPTION_HEADER_PARSERS_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_ENCRYPTION_HEADER_PARSERS_H_ |
6 #define COMPONENTS_GCM_DRIVER_CRYPTO_ENCRYPTION_HEADER_PARSERS_H_ | 6 #define COMPONENTS_GCM_DRIVER_CRYPTO_ENCRYPTION_HEADER_PARSERS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/strings/string_piece.h" |
| 13 #include "net/http/http_util.h" |
| 14 |
12 namespace gcm { | 15 namespace gcm { |
13 | 16 |
14 // Structure representing the parsed values from the Encryption HTTP header. | 17 // Iterates over a header that follows the syntax of the Encryption HTTP header |
15 // |salt| is stored after having been base64url decoded. | 18 // per the Encrypted Content-Encoding for HTTP draft. This header follows the |
16 struct EncryptionHeaderValues { | 19 // #list syntax from the extended ABNF syntax defined in section 1.2 of RFC7230. |
17 std::string keyid; | 20 // |
18 std::string salt; | 21 // https://tools.ietf.org/html/draft-thomson-http-encryption#section-3 |
19 uint64_t rs; | 22 // https://tools.ietf.org/html/rfc7230#section-1.2 |
| 23 class EncryptionHeaderIterator { |
| 24 public: |
| 25 EncryptionHeaderIterator(std::string::const_iterator header_begin, |
| 26 std::string::const_iterator header_end); |
| 27 ~EncryptionHeaderIterator(); |
| 28 |
| 29 // Advances the iterator to the next header value, if any. Returns true if |
| 30 // there is a next value. Use the keyid(), salt() and rs() methods to access |
| 31 // the key-value pairs included in the header value. |
| 32 bool GetNext(); |
| 33 |
| 34 const std::string& keyid() const { |
| 35 return keyid_; |
| 36 } |
| 37 |
| 38 const std::string& salt() const { |
| 39 return salt_; |
| 40 } |
| 41 |
| 42 uint64_t rs() const { |
| 43 return rs_; |
| 44 } |
| 45 |
| 46 private: |
| 47 net::HttpUtil::ValuesIterator iterator_; |
| 48 |
| 49 std::string keyid_; |
| 50 std::string salt_; |
| 51 uint64_t rs_; |
20 }; | 52 }; |
21 | 53 |
22 // Parses |input| following the syntax of the Encryption HTTP header. The parsed | 54 // Iterates over a header that follows the syntax of the Crypto-Key HTTP header |
23 // values will be stored in the |*values| argument. | 55 // per the Encrypted Content-Encoding for HTTP draft. This header follows the |
| 56 // #list syntax from the extended ABNF syntax defined in section 1.2 of RFC7230. |
24 // | 57 // |
25 // https://tools.ietf.org/html/draft-thomson-http-encryption-02#section-3 | 58 // https://tools.ietf.org/html/draft-thomson-http-encryption#section-4 |
26 // | |
27 // This header follows the #list syntax from the extended ABNF syntax | |
28 // defined in section 1.2 of RFC 7230: | |
29 // | |
30 // https://tools.ietf.org/html/rfc7230#section-1.2 | 59 // https://tools.ietf.org/html/rfc7230#section-1.2 |
31 // | 60 class CryptoKeyHeaderIterator { |
32 // Returns whether the |input| could be successfully parsed, and the resulting | 61 public: |
33 // values are now available in the |*values| argument. Does not modify |*values| | 62 CryptoKeyHeaderIterator(std::string::const_iterator header_begin, |
34 // unless parsing was successful. | 63 std::string::const_iterator header_end); |
35 bool ParseEncryptionHeader(const std::string& input, | 64 ~CryptoKeyHeaderIterator(); |
36 std::vector<EncryptionHeaderValues>* values); | |
37 | 65 |
38 // Structure representing the parsed values from the Crypto-Key HTTP header. | 66 // Advances the iterator to the next header value, if any. Returns true if |
39 // |aesgcm128| and |dh| are stored after having been base64url decoded. | 67 // there is a next value. Use the keyid(), aesgcm128() and dh() methods to |
40 struct CryptoKeyHeaderValues { | 68 // access the key-value pairs included in the header value. |
41 std::string keyid; | 69 bool GetNext(); |
42 std::string aesgcm128; | 70 |
43 std::string dh; | 71 const std::string& keyid() const { |
| 72 return keyid_; |
| 73 } |
| 74 |
| 75 const std::string& aesgcm128() const { |
| 76 return aesgcm128_; |
| 77 } |
| 78 |
| 79 const std::string& dh() const { |
| 80 return dh_; |
| 81 } |
| 82 |
| 83 private: |
| 84 net::HttpUtil::ValuesIterator iterator_; |
| 85 |
| 86 std::string keyid_; |
| 87 std::string aesgcm128_; |
| 88 std::string dh_; |
44 }; | 89 }; |
45 | 90 |
46 // Parses |input| following the syntax of the Crypto-Key HTTP header. The parsed | |
47 // values will be stored in the |*values| argument. | |
48 // | |
49 // https://tools.ietf.org/html/draft-thomson-http-encryption-02#section-4 | |
50 // | |
51 // This header follows the #list syntax from the extended ABNF syntax | |
52 // defined in section 1.2 of RFC 7230: | |
53 // | |
54 // https://tools.ietf.org/html/rfc7230#section-1.2 | |
55 // | |
56 // Returns whether the |input| could be successfully parsed, and the resulting | |
57 // values are now available in the |*values| argument. Does not modify |*values| | |
58 // unless parsing was successful. | |
59 bool ParseCryptoKeyHeader(const std::string& input, | |
60 std::vector<CryptoKeyHeaderValues>* values); | |
61 | |
62 } // namespace gcm | 91 } // namespace gcm |
63 | 92 |
64 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_ENCRYPTION_HEADER_PARSERS_H_ | 93 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_ENCRYPTION_HEADER_PARSERS_H_ |
OLD | NEW |