| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/policy/core/common/cloud/policy_builder.h" | 5 #include "components/policy/core/common/cloud/policy_builder.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" |
| 9 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 11 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 10 #include "crypto/signature_creator.h" | 12 #include "crypto/signature_creator.h" |
| 11 | 13 |
| 12 namespace em = enterprise_management; | 14 namespace em = enterprise_management; |
| 13 | 15 |
| 14 namespace policy { | 16 namespace policy { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // Signing key test data in DER-encoded PKCS8 format. | 20 // Signing key test data in DER-encoded PKCS8 format. |
| 19 const uint8 kSigningKey[] = { | 21 const uint8_t kSigningKey[] = { |
| 20 0x30, 0x82, 0x01, 0x55, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 22 0x30, 0x82, 0x01, 0x55, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| 21 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, | 23 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
| 22 0x01, 0x3f, 0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, | 24 0x01, 0x3f, 0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, |
| 23 0xd9, 0xcd, 0xca, 0xcd, 0xc3, 0xea, 0xbe, 0x72, 0x79, 0x1c, 0x29, 0x37, | 25 0xd9, 0xcd, 0xca, 0xcd, 0xc3, 0xea, 0xbe, 0x72, 0x79, 0x1c, 0x29, 0x37, |
| 24 0x39, 0x99, 0x1f, 0xd4, 0xb3, 0x0e, 0xf0, 0x7b, 0x78, 0x77, 0x0e, 0x05, | 26 0x39, 0x99, 0x1f, 0xd4, 0xb3, 0x0e, 0xf0, 0x7b, 0x78, 0x77, 0x0e, 0x05, |
| 25 0x3b, 0x65, 0x34, 0x12, 0x62, 0xaf, 0xa6, 0x8d, 0x33, 0xce, 0x78, 0xf8, | 27 0x3b, 0x65, 0x34, 0x12, 0x62, 0xaf, 0xa6, 0x8d, 0x33, 0xce, 0x78, 0xf8, |
| 26 0x47, 0x05, 0x1d, 0x98, 0xaa, 0x1b, 0x1f, 0x50, 0x05, 0x5b, 0x3c, 0x19, | 28 0x47, 0x05, 0x1d, 0x98, 0xaa, 0x1b, 0x1f, 0x50, 0x05, 0x5b, 0x3c, 0x19, |
| 27 0x3f, 0x80, 0x83, 0x63, 0x63, 0x3a, 0xec, 0xcb, 0x2e, 0x90, 0x4f, 0xf5, | 29 0x3f, 0x80, 0x83, 0x63, 0x63, 0x3a, 0xec, 0xcb, 0x2e, 0x90, 0x4f, 0xf5, |
| 28 0x26, 0x76, 0xf1, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x64, | 30 0x26, 0x76, 0xf1, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x64, |
| 29 0x29, 0xc2, 0xd9, 0x6b, 0xfe, 0xf9, 0x84, 0x75, 0x73, 0xe0, 0xf4, 0x77, | 31 0x29, 0xc2, 0xd9, 0x6b, 0xfe, 0xf9, 0x84, 0x75, 0x73, 0xe0, 0xf4, 0x77, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 0x4f, 0x4d, 0xe1, 0x07, 0x8a, 0x76, 0x87, 0x88, 0x2f, 0x13, 0x35, 0xc1, | 44 0x4f, 0x4d, 0xe1, 0x07, 0x8a, 0x76, 0x87, 0x88, 0x2f, 0x13, 0x35, 0xc1, |
| 43 0x02, 0x20, 0x24, 0xc3, 0xd9, 0x2f, 0x13, 0x47, 0x99, 0x3e, 0x20, 0x59, | 45 0x02, 0x20, 0x24, 0xc3, 0xd9, 0x2f, 0x13, 0x47, 0x99, 0x3e, 0x20, 0x59, |
| 44 0xa1, 0x1a, 0xeb, 0x1c, 0x81, 0x53, 0x38, 0x7e, 0xc5, 0x9e, 0x71, 0xe5, | 46 0xa1, 0x1a, 0xeb, 0x1c, 0x81, 0x53, 0x38, 0x7e, 0xc5, 0x9e, 0x71, 0xe5, |
| 45 0xc0, 0x19, 0x95, 0xdb, 0xef, 0xf6, 0x46, 0xc8, 0x95, 0x3d, 0x02, 0x21, | 47 0xc0, 0x19, 0x95, 0xdb, 0xef, 0xf6, 0x46, 0xc8, 0x95, 0x3d, 0x02, 0x21, |
| 46 0x00, 0xaa, 0xb1, 0xff, 0x8a, 0xa2, 0xb2, 0x2b, 0xef, 0x9a, 0x83, 0x3f, | 48 0x00, 0xaa, 0xb1, 0xff, 0x8a, 0xa2, 0xb2, 0x2b, 0xef, 0x9a, 0x83, 0x3f, |
| 47 0xc5, 0xbc, 0xd4, 0x6a, 0x07, 0xe8, 0xc7, 0x0b, 0x2e, 0xd4, 0x0f, 0xf8, | 49 0xc5, 0xbc, 0xd4, 0x6a, 0x07, 0xe8, 0xc7, 0x0b, 0x2e, 0xd4, 0x0f, 0xf8, |
| 48 0x98, 0x68, 0xe1, 0x04, 0xa8, 0x92, 0xd0, 0x10, 0xaa, | 50 0x98, 0x68, 0xe1, 0x04, 0xa8, 0x92, 0xd0, 0x10, 0xaa, |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 // SHA256 signature of kSigningKey for "example.com" domain. | 53 // SHA256 signature of kSigningKey for "example.com" domain. |
| 52 const uint8 kSigningKeySignature[] = { | 54 const uint8_t kSigningKeySignature[] = { |
| 53 0x97, 0xEB, 0x13, 0xE6, 0x6C, 0xE2, 0x7A, 0x2F, 0xC6, 0x6E, 0x68, 0x8F, | 55 0x97, 0xEB, 0x13, 0xE6, 0x6C, 0xE2, 0x7A, 0x2F, 0xC6, 0x6E, 0x68, 0x8F, |
| 54 0xED, 0x5B, 0x51, 0x08, 0x27, 0xF0, 0xA5, 0x97, 0x20, 0xEE, 0xE2, 0x9B, | 56 0xED, 0x5B, 0x51, 0x08, 0x27, 0xF0, 0xA5, 0x97, 0x20, 0xEE, 0xE2, 0x9B, |
| 55 0x5B, 0x63, 0xA5, 0x9C, 0xAE, 0x41, 0xFD, 0x34, 0xC4, 0x2E, 0xEB, 0x63, | 57 0x5B, 0x63, 0xA5, 0x9C, 0xAE, 0x41, 0xFD, 0x34, 0xC4, 0x2E, 0xEB, 0x63, |
| 56 0x10, 0x80, 0x0C, 0x74, 0x77, 0x6E, 0x34, 0x1C, 0x1B, 0x3B, 0x8E, 0x2A, | 58 0x10, 0x80, 0x0C, 0x74, 0x77, 0x6E, 0x34, 0x1C, 0x1B, 0x3B, 0x8E, 0x2A, |
| 57 0x3A, 0x7F, 0xF9, 0x73, 0xB6, 0x2B, 0xB6, 0x45, 0xDB, 0x05, 0xE8, 0x5A, | 59 0x3A, 0x7F, 0xF9, 0x73, 0xB6, 0x2B, 0xB6, 0x45, 0xDB, 0x05, 0xE8, 0x5A, |
| 58 0x68, 0x36, 0x05, 0x3C, 0x62, 0x3A, 0x6C, 0x64, 0xDB, 0x0E, 0x61, 0xBD, | 60 0x68, 0x36, 0x05, 0x3C, 0x62, 0x3A, 0x6C, 0x64, 0xDB, 0x0E, 0x61, 0xBD, |
| 59 0x29, 0x1C, 0x61, 0x4B, 0xE0, 0xDA, 0x07, 0xBA, 0x29, 0x81, 0xF0, 0x90, | 61 0x29, 0x1C, 0x61, 0x4B, 0xE0, 0xDA, 0x07, 0xBA, 0x29, 0x81, 0xF0, 0x90, |
| 60 0x58, 0xB8, 0xBB, 0xF4, 0x69, 0xFF, 0x8F, 0x2B, 0x4A, 0x2D, 0x98, 0x51, | 62 0x58, 0xB8, 0xBB, 0xF4, 0x69, 0xFF, 0x8F, 0x2B, 0x4A, 0x2D, 0x98, 0x51, |
| 61 0x37, 0xF5, 0x52, 0xCB, 0xE3, 0xC4, 0x6D, 0xEC, 0xEA, 0x32, 0x2D, 0xDD, | 63 0x37, 0xF5, 0x52, 0xCB, 0xE3, 0xC4, 0x6D, 0xEC, 0xEA, 0x32, 0x2D, 0xDD, |
| 62 0xD7, 0xFC, 0x43, 0xC6, 0x54, 0xE1, 0xC1, 0x66, 0x43, 0x37, 0x09, 0xE1, | 64 0xD7, 0xFC, 0x43, 0xC6, 0x54, 0xE1, 0xC1, 0x66, 0x43, 0x37, 0x09, 0xE1, |
| 63 0xBF, 0xD1, 0x11, 0xFC, 0xDB, 0xBF, 0xDF, 0x66, 0x53, 0x8F, 0x38, 0x2D, | 65 0xBF, 0xD1, 0x11, 0xFC, 0xDB, 0xBF, 0xDF, 0x66, 0x53, 0x8F, 0x38, 0x2D, |
| 64 0xAA, 0x89, 0xD2, 0x9F, 0x60, 0x90, 0xB7, 0x05, 0xC2, 0x20, 0x82, 0xE6, | 66 0xAA, 0x89, 0xD2, 0x9F, 0x60, 0x90, 0xB7, 0x05, 0xC2, 0x20, 0x82, 0xE6, |
| 65 0xE0, 0x57, 0x55, 0xFF, 0x5F, 0xC1, 0x76, 0x66, 0x46, 0xF8, 0x67, 0xB8, | 67 0xE0, 0x57, 0x55, 0xFF, 0x5F, 0xC1, 0x76, 0x66, 0x46, 0xF8, 0x67, 0xB8, |
| 66 0x8B, 0x81, 0x53, 0xA9, 0x8B, 0x48, 0x9E, 0x2A, 0xF9, 0x60, 0x57, 0xBA, | 68 0x8B, 0x81, 0x53, 0xA9, 0x8B, 0x48, 0x9E, 0x2A, 0xF9, 0x60, 0x57, 0xBA, |
| 67 0xD7, 0x52, 0x97, 0x53, 0xF0, 0x2F, 0x78, 0x68, 0x50, 0x18, 0x12, 0x00, | 69 0xD7, 0x52, 0x97, 0x53, 0xF0, 0x2F, 0x78, 0x68, 0x50, 0x18, 0x12, 0x00, |
| 68 0x5E, 0x8E, 0x2A, 0x62, 0x0D, 0x48, 0xA9, 0xB5, 0x6B, 0xBC, 0xA0, 0x52, | 70 0x5E, 0x8E, 0x2A, 0x62, 0x0D, 0x48, 0xA9, 0xB5, 0x6B, 0xBC, 0xA0, 0x52, |
| 69 0x53, 0xD7, 0x65, 0x23, 0xA4, 0xA5, 0xF5, 0x32, 0x49, 0x2D, 0xB2, 0x77, | 71 0x53, 0xD7, 0x65, 0x23, 0xA4, 0xA5, 0xF5, 0x32, 0x49, 0x2D, 0xB2, 0x77, |
| 70 0x2C, 0x66, 0x97, 0xBA, 0x58, 0xE0, 0x16, 0x1C, 0x8C, 0x02, 0x5D, 0xE0, | 72 0x2C, 0x66, 0x97, 0xBA, 0x58, 0xE0, 0x16, 0x1C, 0x8C, 0x02, 0x5D, 0xE0, |
| 71 0x73, 0x2E, 0xDF, 0xB4, 0x2F, 0x4C, 0xA2, 0x11, 0x26, 0xC1, 0xAF, 0xAC, | 73 0x73, 0x2E, 0xDF, 0xB4, 0x2F, 0x4C, 0xA2, 0x11, 0x26, 0xC1, 0xAF, 0xAC, |
| 72 0x73, 0xBC, 0xB6, 0x98, 0xE0, 0x20, 0x61, 0x0E, 0x52, 0x4A, 0x6C, 0x80, | 74 0x73, 0xBC, 0xB6, 0x98, 0xE0, 0x20, 0x61, 0x0E, 0x52, 0x4A, 0x6C, 0x80, |
| 73 0xB5, 0x0C, 0x10, 0x80, 0x09, 0x17, 0xF4, 0x9D, 0xFE, 0xB5, 0xFC, 0x63, | 75 0xB5, 0x0C, 0x10, 0x80, 0x09, 0x17, 0xF4, 0x9D, 0xFE, 0xB5, 0xFC, 0x63, |
| 74 0x9A, 0x80, 0x3F, 0x76, | 76 0x9A, 0x80, 0x3F, 0x76, |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 // New signing key test data in DER-encoded PKCS8 format. | 79 // New signing key test data in DER-encoded PKCS8 format. |
| 78 const uint8 kNewSigningKey[] = { | 80 const uint8_t kNewSigningKey[] = { |
| 79 0x30, 0x82, 0x01, 0x54, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 81 0x30, 0x82, 0x01, 0x54, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| 80 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, | 82 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
| 81 0x01, 0x3e, 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, | 83 0x01, 0x3e, 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, |
| 82 0x99, 0x98, 0x6b, 0x79, 0x5d, 0x38, 0x33, 0x79, 0x27, 0x0a, 0x2e, 0xb0, | 84 0x99, 0x98, 0x6b, 0x79, 0x5d, 0x38, 0x33, 0x79, 0x27, 0x0a, 0x2e, 0xb0, |
| 83 0x89, 0xba, 0xf8, 0xf6, 0x80, 0xde, 0xb0, 0x79, 0xf2, 0xd4, 0x6d, 0xf7, | 85 0x89, 0xba, 0xf8, 0xf6, 0x80, 0xde, 0xb0, 0x79, 0xf2, 0xd4, 0x6d, 0xf7, |
| 84 0x3c, 0xa3, 0x97, 0xf6, 0x4a, 0x3c, 0xa5, 0xcc, 0x40, 0x8a, 0xef, 0x59, | 86 0x3c, 0xa3, 0x97, 0xf6, 0x4a, 0x3c, 0xa5, 0xcc, 0x40, 0x8a, 0xef, 0x59, |
| 85 0xaa, 0xc2, 0x82, 0x8f, 0xbc, 0x0d, 0x5b, 0x63, 0xc6, 0xaa, 0x72, 0xe2, | 87 0xaa, 0xc2, 0x82, 0x8f, 0xbc, 0x0d, 0x5b, 0x63, 0xc6, 0xaa, 0x72, 0xe2, |
| 86 0xf3, 0x57, 0xdd, 0x74, 0x00, 0xb0, 0x42, 0xd6, 0x27, 0xe7, 0x17, 0x61, | 88 0xf3, 0x57, 0xdd, 0x74, 0x00, 0xb0, 0x42, 0xd6, 0x27, 0xe7, 0x17, 0x61, |
| 87 0x0a, 0xdc, 0xc1, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x34, | 89 0x0a, 0xdc, 0xc1, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x34, |
| 88 0xcf, 0xc9, 0xb4, 0x73, 0x2f, 0x0d, 0xd3, 0xcc, 0x6e, 0x9d, 0xdb, 0x29, | 90 0xcf, 0xc9, 0xb4, 0x73, 0x2f, 0x0d, 0xd3, 0xcc, 0x6e, 0x9d, 0xdb, 0x29, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 0x2e, 0xeb, 0x7d, 0x70, 0x00, 0xe9, 0xeb, 0x88, 0xfa, 0x40, 0xc9, 0x02, | 103 0x2e, 0xeb, 0x7d, 0x70, 0x00, 0xe9, 0xeb, 0x88, 0xfa, 0x40, 0xc9, 0x02, |
| 102 0x20, 0x3a, 0xe0, 0xc4, 0xde, 0x10, 0x6e, 0x6a, 0xe1, 0x68, 0x00, 0x26, | 104 0x20, 0x3a, 0xe0, 0xc4, 0xde, 0x10, 0x6e, 0x6a, 0xe1, 0x68, 0x00, 0x26, |
| 103 0xb6, 0x21, 0x8a, 0x13, 0x5c, 0x2b, 0x96, 0x00, 0xb0, 0x08, 0x8b, 0x15, | 105 0xb6, 0x21, 0x8a, 0x13, 0x5c, 0x2b, 0x96, 0x00, 0xb0, 0x08, 0x8b, 0x15, |
| 104 0x6a, 0x68, 0x9a, 0xb1, 0x23, 0x8a, 0x02, 0xa2, 0xe1, 0x02, 0x21, 0x00, | 106 0x6a, 0x68, 0x9a, 0xb1, 0x23, 0x8a, 0x02, 0xa2, 0xe1, 0x02, 0x21, 0x00, |
| 105 0xa3, 0xf2, 0x2d, 0x55, 0xc1, 0x6d, 0x40, 0xfa, 0x1d, 0xf7, 0xba, 0x86, | 107 0xa3, 0xf2, 0x2d, 0x55, 0xc1, 0x6d, 0x40, 0xfa, 0x1d, 0xf7, 0xba, 0x86, |
| 106 0xef, 0x50, 0x98, 0xfc, 0xee, 0x09, 0xcc, 0xe7, 0x22, 0xb9, 0x4e, 0x80, | 108 0xef, 0x50, 0x98, 0xfc, 0xee, 0x09, 0xcc, 0xe7, 0x22, 0xb9, 0x4e, 0x80, |
| 107 0x32, 0x1a, 0x6b, 0xb3, 0x5f, 0x35, 0xbd, 0xf3, | 109 0x32, 0x1a, 0x6b, 0xb3, 0x5f, 0x35, 0xbd, 0xf3, |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 // SHA256 signature of kNewSigningKey for "example.com" domain. | 112 // SHA256 signature of kNewSigningKey for "example.com" domain. |
| 111 const uint8 kNewSigningKeySignature[] = { | 113 const uint8_t kNewSigningKeySignature[] = { |
| 112 0x70, 0xED, 0x27, 0x42, 0x34, 0x69, 0xB6, 0x47, 0x9E, 0x7C, 0xA0, 0xF0, | 114 0x70, 0xED, 0x27, 0x42, 0x34, 0x69, 0xB6, 0x47, 0x9E, 0x7C, 0xA0, 0xF0, |
| 113 0xE5, 0x0A, 0x49, 0x49, 0x00, 0xDA, 0xBC, 0x70, 0x01, 0xC5, 0x4B, 0xDB, | 115 0xE5, 0x0A, 0x49, 0x49, 0x00, 0xDA, 0xBC, 0x70, 0x01, 0xC5, 0x4B, 0xDB, |
| 114 0x47, 0xD5, 0xAF, 0xA1, 0xAD, 0xB7, 0xE4, 0xE1, 0xBD, 0x5A, 0x1C, 0x35, | 116 0x47, 0xD5, 0xAF, 0xA1, 0xAD, 0xB7, 0xE4, 0xE1, 0xBD, 0x5A, 0x1C, 0x35, |
| 115 0x44, 0x5A, 0xAA, 0xDB, 0x27, 0xBA, 0xA4, 0xA9, 0xC8, 0xDD, 0xEC, 0xD6, | 117 0x44, 0x5A, 0xAA, 0xDB, 0x27, 0xBA, 0xA4, 0xA9, 0xC8, 0xDD, 0xEC, 0xD6, |
| 116 0xEB, 0xFE, 0xDB, 0xE0, 0x03, 0x5C, 0xA6, 0x2E, 0x5A, 0xEC, 0x75, 0x79, | 118 0xEB, 0xFE, 0xDB, 0xE0, 0x03, 0x5C, 0xA6, 0x2E, 0x5A, 0xEC, 0x75, 0x79, |
| 117 0xB8, 0x5F, 0x0A, 0xEE, 0x05, 0xB2, 0x61, 0xDC, 0x58, 0xF0, 0xD1, 0xCB, | 119 0xB8, 0x5F, 0x0A, 0xEE, 0x05, 0xB2, 0x61, 0xDC, 0x58, 0xF0, 0xD1, 0xCB, |
| 118 0x7B, 0x2A, 0xDB, 0xC1, 0x7C, 0x60, 0xE6, 0x3E, 0x87, 0x02, 0x61, 0xE6, | 120 0x7B, 0x2A, 0xDB, 0xC1, 0x7C, 0x60, 0xE6, 0x3E, 0x87, 0x02, 0x61, 0xE6, |
| 119 0x90, 0xFD, 0x54, 0x65, 0xC7, 0xFF, 0x74, 0x09, 0xD6, 0xAA, 0x8E, 0xDC, | 121 0x90, 0xFD, 0x54, 0x65, 0xC7, 0xFF, 0x74, 0x09, 0xD6, 0xAA, 0x8E, 0xDC, |
| 120 0x5B, 0xC8, 0x38, 0x0C, 0x84, 0x0E, 0x84, 0x2E, 0x37, 0x2A, 0x4B, 0xDE, | 122 0x5B, 0xC8, 0x38, 0x0C, 0x84, 0x0E, 0x84, 0x2E, 0x37, 0x2A, 0x4B, 0xDE, |
| 121 0x31, 0x82, 0x76, 0x1E, 0x77, 0xA5, 0xC1, 0xD5, 0xED, 0xFF, 0xBC, 0xEA, | 123 0x31, 0x82, 0x76, 0x1E, 0x77, 0xA5, 0xC1, 0xD5, 0xED, 0xFF, 0xBC, 0xEA, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 }; | 136 }; |
| 135 | 137 |
| 136 } // namespace | 138 } // namespace |
| 137 | 139 |
| 138 // Constants used as dummy data for filling the PolicyData protobuf. | 140 // Constants used as dummy data for filling the PolicyData protobuf. |
| 139 const char PolicyBuilder::kFakeDeviceId[] = "device-id"; | 141 const char PolicyBuilder::kFakeDeviceId[] = "device-id"; |
| 140 const char PolicyBuilder::kFakeDomain[] = "example.com"; | 142 const char PolicyBuilder::kFakeDomain[] = "example.com"; |
| 141 const char PolicyBuilder::kFakeMachineName[] = "machine-name"; | 143 const char PolicyBuilder::kFakeMachineName[] = "machine-name"; |
| 142 const char PolicyBuilder::kFakePolicyType[] = "policy type"; | 144 const char PolicyBuilder::kFakePolicyType[] = "policy type"; |
| 143 const int PolicyBuilder::kFakePublicKeyVersion = 17; | 145 const int PolicyBuilder::kFakePublicKeyVersion = 17; |
| 144 const int64 PolicyBuilder::kFakeTimestamp = 365LL * 24 * 60 * 60 * 1000; | 146 const int64_t PolicyBuilder::kFakeTimestamp = 365LL * 24 * 60 * 60 * 1000; |
| 145 const char PolicyBuilder::kFakeToken[] = "token"; | 147 const char PolicyBuilder::kFakeToken[] = "token"; |
| 146 const char PolicyBuilder::kFakeUsername[] = "username@example.com"; | 148 const char PolicyBuilder::kFakeUsername[] = "username@example.com"; |
| 147 const char PolicyBuilder::kFakeServiceAccountIdentity[] = "robot4test@g.com"; | 149 const char PolicyBuilder::kFakeServiceAccountIdentity[] = "robot4test@g.com"; |
| 148 | 150 |
| 149 PolicyBuilder::PolicyBuilder() | 151 PolicyBuilder::PolicyBuilder() |
| 150 : policy_data_(new em::PolicyData()) { | 152 : policy_data_(new em::PolicyData()) { |
| 151 SetDefaultSigningKey(); | 153 SetDefaultSigningKey(); |
| 152 policy_data_->set_policy_type(kFakePolicyType); | 154 policy_data_->set_policy_type(kFakePolicyType); |
| 153 policy_data_->set_timestamp(kFakeTimestamp); | 155 policy_data_->set_timestamp(kFakeTimestamp); |
| 154 policy_data_->set_request_token(kFakeToken); | 156 policy_data_->set_request_token(kFakeToken); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 return scoped_ptr<crypto::RSAPrivateKey>(); | 169 return scoped_ptr<crypto::RSAPrivateKey>(); |
| 168 return scoped_ptr<crypto::RSAPrivateKey>( | 170 return scoped_ptr<crypto::RSAPrivateKey>( |
| 169 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_signing_key_)); | 171 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_signing_key_)); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void PolicyBuilder::SetSigningKey(const crypto::RSAPrivateKey& key) { | 174 void PolicyBuilder::SetSigningKey(const crypto::RSAPrivateKey& key) { |
| 173 key.ExportPrivateKey(&raw_signing_key_); | 175 key.ExportPrivateKey(&raw_signing_key_); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void PolicyBuilder::SetDefaultSigningKey() { | 178 void PolicyBuilder::SetDefaultSigningKey() { |
| 177 std::vector<uint8> key(kSigningKey, kSigningKey + arraysize(kSigningKey)); | 179 std::vector<uint8_t> key(kSigningKey, kSigningKey + arraysize(kSigningKey)); |
| 178 raw_signing_key_.swap(key); | 180 raw_signing_key_.swap(key); |
| 179 } | 181 } |
| 180 | 182 |
| 181 void PolicyBuilder::UnsetSigningKey() { | 183 void PolicyBuilder::UnsetSigningKey() { |
| 182 raw_signing_key_.clear(); | 184 raw_signing_key_.clear(); |
| 183 } | 185 } |
| 184 | 186 |
| 185 scoped_ptr<crypto::RSAPrivateKey> PolicyBuilder::GetNewSigningKey() { | 187 scoped_ptr<crypto::RSAPrivateKey> PolicyBuilder::GetNewSigningKey() { |
| 186 if (raw_new_signing_key_.empty()) | 188 if (raw_new_signing_key_.empty()) |
| 187 return scoped_ptr<crypto::RSAPrivateKey>(); | 189 return scoped_ptr<crypto::RSAPrivateKey>(); |
| 188 return scoped_ptr<crypto::RSAPrivateKey>( | 190 return scoped_ptr<crypto::RSAPrivateKey>( |
| 189 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_new_signing_key_)); | 191 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_new_signing_key_)); |
| 190 } | 192 } |
| 191 | 193 |
| 192 void PolicyBuilder::SetDefaultNewSigningKey() { | 194 void PolicyBuilder::SetDefaultNewSigningKey() { |
| 193 std::vector<uint8> key(kNewSigningKey, | 195 std::vector<uint8_t> key(kNewSigningKey, |
| 194 kNewSigningKey + arraysize(kNewSigningKey)); | 196 kNewSigningKey + arraysize(kNewSigningKey)); |
| 195 raw_new_signing_key_.swap(key); | 197 raw_new_signing_key_.swap(key); |
| 196 raw_new_signing_key_signature_ = GetTestOtherSigningKeySignature(); | 198 raw_new_signing_key_signature_ = GetTestOtherSigningKeySignature(); |
| 197 } | 199 } |
| 198 | 200 |
| 199 void PolicyBuilder::SetDefaultInitialSigningKey() { | 201 void PolicyBuilder::SetDefaultInitialSigningKey() { |
| 200 std::vector<uint8> key(kSigningKey, | 202 std::vector<uint8_t> key(kSigningKey, kSigningKey + arraysize(kSigningKey)); |
| 201 kSigningKey + arraysize(kSigningKey)); | |
| 202 raw_new_signing_key_.swap(key); | 203 raw_new_signing_key_.swap(key); |
| 203 raw_new_signing_key_signature_ = GetTestSigningKeySignature(); | 204 raw_new_signing_key_signature_ = GetTestSigningKeySignature(); |
| 204 UnsetSigningKey(); | 205 UnsetSigningKey(); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void PolicyBuilder::UnsetNewSigningKey() { | 208 void PolicyBuilder::UnsetNewSigningKey() { |
| 208 raw_new_signing_key_.clear(); | 209 raw_new_signing_key_.clear(); |
| 209 raw_new_signing_key_signature_.clear(); | 210 raw_new_signing_key_signature_.clear(); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void PolicyBuilder::Build() { | 213 void PolicyBuilder::Build() { |
| 213 // Generate signatures if applicable. | 214 // Generate signatures if applicable. |
| 214 scoped_ptr<crypto::RSAPrivateKey> policy_signing_key = GetNewSigningKey(); | 215 scoped_ptr<crypto::RSAPrivateKey> policy_signing_key = GetNewSigningKey(); |
| 215 if (policy_signing_key) { | 216 if (policy_signing_key) { |
| 216 // Add the new public key. | 217 // Add the new public key. |
| 217 std::vector<uint8> raw_new_public_signing_key; | 218 std::vector<uint8_t> raw_new_public_signing_key; |
| 218 CHECK(policy_signing_key->ExportPublicKey(&raw_new_public_signing_key)); | 219 CHECK(policy_signing_key->ExportPublicKey(&raw_new_public_signing_key)); |
| 219 policy_.set_new_public_key(raw_new_public_signing_key.data(), | 220 policy_.set_new_public_key(raw_new_public_signing_key.data(), |
| 220 raw_new_public_signing_key.size()); | 221 raw_new_public_signing_key.size()); |
| 221 | 222 |
| 222 policy_.set_new_public_key_verification_signature( | 223 policy_.set_new_public_key_verification_signature( |
| 223 raw_new_signing_key_signature_); | 224 raw_new_signing_key_signature_); |
| 224 | 225 |
| 225 // The new public key must be signed by the old key. | 226 // The new public key must be signed by the old key. |
| 226 scoped_ptr<crypto::RSAPrivateKey> old_signing_key = GetSigningKey(); | 227 scoped_ptr<crypto::RSAPrivateKey> old_signing_key = GetSigningKey(); |
| 227 if (old_signing_key) { | 228 if (old_signing_key) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 257 } | 258 } |
| 258 | 259 |
| 259 scoped_ptr<em::PolicyFetchResponse> PolicyBuilder::GetCopy() { | 260 scoped_ptr<em::PolicyFetchResponse> PolicyBuilder::GetCopy() { |
| 260 scoped_ptr<em::PolicyFetchResponse> result(new em::PolicyFetchResponse()); | 261 scoped_ptr<em::PolicyFetchResponse> result(new em::PolicyFetchResponse()); |
| 261 result->CopyFrom(policy_); | 262 result->CopyFrom(policy_); |
| 262 return result.Pass(); | 263 return result.Pass(); |
| 263 } | 264 } |
| 264 | 265 |
| 265 // static | 266 // static |
| 266 scoped_ptr<crypto::RSAPrivateKey> PolicyBuilder::CreateTestSigningKey() { | 267 scoped_ptr<crypto::RSAPrivateKey> PolicyBuilder::CreateTestSigningKey() { |
| 267 std::vector<uint8> raw_signing_key( | 268 std::vector<uint8_t> raw_signing_key(kSigningKey, |
| 268 kSigningKey, kSigningKey + arraysize(kSigningKey)); | 269 kSigningKey + arraysize(kSigningKey)); |
| 269 return scoped_ptr<crypto::RSAPrivateKey>( | 270 return scoped_ptr<crypto::RSAPrivateKey>( |
| 270 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_signing_key)); | 271 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_signing_key)); |
| 271 } | 272 } |
| 272 | 273 |
| 273 // static | 274 // static |
| 274 scoped_ptr<crypto::RSAPrivateKey> PolicyBuilder::CreateTestOtherSigningKey() { | 275 scoped_ptr<crypto::RSAPrivateKey> PolicyBuilder::CreateTestOtherSigningKey() { |
| 275 std::vector<uint8> raw_new_signing_key( | 276 std::vector<uint8_t> raw_new_signing_key( |
| 276 kNewSigningKey, kNewSigningKey + arraysize(kNewSigningKey)); | 277 kNewSigningKey, kNewSigningKey + arraysize(kNewSigningKey)); |
| 277 return scoped_ptr<crypto::RSAPrivateKey>( | 278 return scoped_ptr<crypto::RSAPrivateKey>( |
| 278 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_new_signing_key)); | 279 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_new_signing_key)); |
| 279 } | 280 } |
| 280 | 281 |
| 281 // static | 282 // static |
| 282 std::string PolicyBuilder::GetTestSigningKeySignature() { | 283 std::string PolicyBuilder::GetTestSigningKeySignature() { |
| 283 return std::string(reinterpret_cast<const char*>(kSigningKeySignature), | 284 return std::string(reinterpret_cast<const char*>(kSigningKeySignature), |
| 284 sizeof(kSigningKeySignature)); | 285 sizeof(kSigningKeySignature)); |
| 285 } | 286 } |
| 286 | 287 |
| 287 // static | 288 // static |
| 288 std::string PolicyBuilder::GetTestOtherSigningKeySignature() { | 289 std::string PolicyBuilder::GetTestOtherSigningKeySignature() { |
| 289 return std::string(reinterpret_cast<const char*>(kNewSigningKeySignature), | 290 return std::string(reinterpret_cast<const char*>(kNewSigningKeySignature), |
| 290 sizeof(kNewSigningKeySignature)); | 291 sizeof(kNewSigningKeySignature)); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void PolicyBuilder::SignData(const std::string& data, | 294 void PolicyBuilder::SignData(const std::string& data, |
| 294 crypto::RSAPrivateKey* key, | 295 crypto::RSAPrivateKey* key, |
| 295 std::string* signature) { | 296 std::string* signature) { |
| 296 scoped_ptr<crypto::SignatureCreator> signature_creator( | 297 scoped_ptr<crypto::SignatureCreator> signature_creator( |
| 297 crypto::SignatureCreator::Create(key, | 298 crypto::SignatureCreator::Create(key, |
| 298 crypto::SignatureCreator::SHA1)); | 299 crypto::SignatureCreator::SHA1)); |
| 299 signature_creator->Update(reinterpret_cast<const uint8*>(data.c_str()), | 300 signature_creator->Update(reinterpret_cast<const uint8_t*>(data.c_str()), |
| 300 data.size()); | 301 data.size()); |
| 301 std::vector<uint8> signature_bytes; | 302 std::vector<uint8_t> signature_bytes; |
| 302 CHECK(signature_creator->Final(&signature_bytes)); | 303 CHECK(signature_creator->Final(&signature_bytes)); |
| 303 signature->assign(reinterpret_cast<const char*>(signature_bytes.data()), | 304 signature->assign(reinterpret_cast<const char*>(signature_bytes.data()), |
| 304 signature_bytes.size()); | 305 signature_bytes.size()); |
| 305 } | 306 } |
| 306 | 307 |
| 307 template<> | 308 template<> |
| 308 TypedPolicyBuilder<em::CloudPolicySettings>::TypedPolicyBuilder() | 309 TypedPolicyBuilder<em::CloudPolicySettings>::TypedPolicyBuilder() |
| 309 : payload_(new em::CloudPolicySettings()) { | 310 : payload_(new em::CloudPolicySettings()) { |
| 310 policy_data().set_policy_type(dm_protocol::kChromeUserPolicyType); | 311 policy_data().set_policy_type(dm_protocol::kChromeUserPolicyType); |
| 311 } | 312 } |
| 312 | 313 |
| 313 // Have the instantiation compiled into the module. | 314 // Have the instantiation compiled into the module. |
| 314 template class TypedPolicyBuilder<em::CloudPolicySettings>; | 315 template class TypedPolicyBuilder<em::CloudPolicySettings>; |
| 315 | 316 |
| 316 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 317 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 317 template<> | 318 template<> |
| 318 TypedPolicyBuilder<em::ExternalPolicyData>::TypedPolicyBuilder() | 319 TypedPolicyBuilder<em::ExternalPolicyData>::TypedPolicyBuilder() |
| 319 : payload_(new em::ExternalPolicyData()) { | 320 : payload_(new em::ExternalPolicyData()) { |
| 320 policy_data().set_policy_type(dm_protocol::kChromeExtensionPolicyType); | 321 policy_data().set_policy_type(dm_protocol::kChromeExtensionPolicyType); |
| 321 } | 322 } |
| 322 | 323 |
| 323 template class TypedPolicyBuilder<em::ExternalPolicyData>; | 324 template class TypedPolicyBuilder<em::ExternalPolicyData>; |
| 324 #endif | 325 #endif |
| 325 | 326 |
| 326 } // namespace policy | 327 } // namespace policy |
| OLD | NEW |