File: policy_builder.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (684 lines) | stat: -rw-r--r-- 34,857 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/policy/core/common/cloud/test/policy_builder.h"

#include <vector>

#include "base/base64.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "crypto/signature_creator.h"
#include "google_apis/gaia/gaia_id.h"

namespace em = enterprise_management;

namespace policy {

const uint8_t kVerificationPrivateKey[] = {
    0x30, 0x82, 0x04, 0xbe, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
    0x04, 0xa8, 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01,
    0x01, 0x00, 0xb2, 0x68, 0xc7, 0xcd, 0xd1, 0xd5, 0xac, 0xe1, 0xb9, 0xfc,
    0x97, 0xbd, 0x94, 0x5e, 0xef, 0x1b, 0xf6, 0x0d, 0xea, 0x47, 0xc8, 0xb0,
    0x8f, 0xa2, 0xb2, 0x17, 0xa3, 0xd5, 0x3f, 0x1d, 0x40, 0x0c, 0x26, 0xa6,
    0xf3, 0xc4, 0xb9, 0xc6, 0xbe, 0x8c, 0x79, 0xe1, 0x92, 0x26, 0xd9, 0xae,
    0x2d, 0xdb, 0x3f, 0xbb, 0x62, 0xda, 0x1b, 0x28, 0x70, 0x1d, 0x60, 0x65,
    0xb9, 0x70, 0x21, 0x0e, 0x57, 0xad, 0x28, 0x52, 0x17, 0x74, 0xf2, 0x8d,
    0x86, 0x86, 0x47, 0xad, 0xd5, 0x8c, 0xfe, 0xb3, 0x71, 0x81, 0x9f, 0x74,
    0x6b, 0x66, 0x4c, 0x32, 0x8d, 0xb4, 0x45, 0x5a, 0xe1, 0x06, 0xc2, 0x45,
    0xc1, 0xa5, 0xcd, 0x6d, 0x2d, 0xb2, 0x43, 0x63, 0xd8, 0xaa, 0xb9, 0x1b,
    0xa5, 0x53, 0x9b, 0xe7, 0x75, 0xc0, 0x0d, 0x7c, 0xc8, 0xdc, 0x54, 0x4b,
    0xde, 0xb6, 0x7b, 0x6e, 0x8f, 0xfc, 0xfc, 0x39, 0xbd, 0x06, 0x32, 0xfc,
    0x6f, 0x47, 0xab, 0x68, 0xab, 0x66, 0x98, 0x50, 0xe0, 0x94, 0xfb, 0x7c,
    0x15, 0x03, 0xf2, 0xa5, 0xd6, 0x61, 0xa7, 0x70, 0x57, 0x49, 0x8f, 0x26,
    0x75, 0x30, 0x99, 0xa3, 0xd7, 0xa3, 0xd0, 0xb8, 0x26, 0xd9, 0xeb, 0x7f,
    0xff, 0xc6, 0xa0, 0x62, 0x0b, 0xc5, 0x38, 0xd6, 0x34, 0xc5, 0xaf, 0xb3,
    0x93, 0x09, 0xaf, 0x37, 0xfc, 0x98, 0x80, 0xf2, 0xf2, 0x5b, 0x5d, 0xce,
    0xa5, 0x0e, 0xc7, 0x44, 0x31, 0x87, 0x24, 0x00, 0xf7, 0xcd, 0xdd, 0xe1,
    0xc8, 0xfe, 0xde, 0x46, 0x68, 0x93, 0xe9, 0x3c, 0x1f, 0xad, 0x8a, 0xa6,
    0xf5, 0x5f, 0x1f, 0x0c, 0x6a, 0xa1, 0x1c, 0x39, 0xe1, 0xb5, 0x71, 0xa3,
    0x4f, 0x2f, 0x62, 0x48, 0xcd, 0x52, 0x65, 0x58, 0x7b, 0x84, 0x40, 0x31,
    0x14, 0x4e, 0x01, 0x58, 0x4e, 0x89, 0x9b, 0x3a, 0x04, 0x3e, 0x0f, 0x9d,
    0x66, 0xf0, 0x97, 0x66, 0xcd, 0x8f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02,
    0x82, 0x01, 0x00, 0x0e, 0xe1, 0x9b, 0x8c, 0xe8, 0xec, 0x4c, 0x4b, 0xd5,
    0xc2, 0x22, 0x7c, 0x0f, 0x34, 0xad, 0xf8, 0x24, 0x99, 0x7b, 0x89, 0xba,
    0x4d, 0x33, 0xe5, 0xeb, 0xb9, 0xfa, 0x11, 0xee, 0xfe, 0x47, 0x19, 0xdc,
    0x5d, 0x7f, 0xa6, 0xd0, 0xa2, 0x29, 0xc1, 0xb8, 0xe6, 0xde, 0x54, 0x7c,
    0x42, 0xc1, 0x93, 0x70, 0xa8, 0xf6, 0x31, 0x60, 0x23, 0x8a, 0xda, 0x80,
    0x70, 0x6b, 0xbb, 0xd5, 0x1e, 0x07, 0xa5, 0x2b, 0x60, 0x51, 0x91, 0x91,
    0x2b, 0xc9, 0xe5, 0x48, 0x74, 0x51, 0x04, 0x3e, 0x38, 0x84, 0x86, 0xbd,
    0xe0, 0xad, 0x96, 0xae, 0x53, 0x67, 0x2b, 0x7a, 0xbf, 0x7e, 0x56, 0x9c,
    0x7c, 0xca, 0x0e, 0xc4, 0xe8, 0x4e, 0xef, 0xf8, 0x1c, 0x0b, 0x76, 0x0e,
    0x13, 0xa6, 0xc2, 0x27, 0x16, 0x72, 0xe5, 0x6e, 0x9a, 0x92, 0x7c, 0x82,
    0x51, 0x83, 0xc5, 0xaf, 0xdd, 0x04, 0x88, 0xa3, 0x17, 0x43, 0xd3, 0x6d,
    0x62, 0x88, 0xc2, 0xd7, 0x12, 0x23, 0xe0, 0xd5, 0xba, 0x26, 0x20, 0x18,
    0x64, 0x81, 0x89, 0xb4, 0xa7, 0xe2, 0xdb, 0x84, 0xb4, 0xc0, 0x2a, 0x34,
    0x99, 0x7f, 0x7d, 0x22, 0x7b, 0x6b, 0x46, 0x21, 0x00, 0x57, 0x9a, 0x96,
    0x4c, 0x4a, 0x01, 0x8d, 0x28, 0xd3, 0xb6, 0xb2, 0xa2, 0xbf, 0xa5, 0x7f,
    0x7c, 0x97, 0xfa, 0x8b, 0xc5, 0x4f, 0xa4, 0x52, 0x9a, 0xb5, 0xad, 0x1c,
    0x05, 0xb9, 0x9a, 0x96, 0x09, 0x9d, 0x43, 0x6f, 0x82, 0x8a, 0x82, 0x6d,
    0x6c, 0x90, 0x49, 0x37, 0xe1, 0xad, 0x6d, 0x5b, 0x7d, 0xb3, 0xe9, 0xd3,
    0xb5, 0xdf, 0x87, 0x86, 0x0a, 0x96, 0x3b, 0xe1, 0x92, 0x50, 0x56, 0x07,
    0x9b, 0xf0, 0xf7, 0xf3, 0xca, 0x9e, 0x88, 0xab, 0xb1, 0x31, 0x79, 0xd8,
    0xe6, 0xf5, 0x17, 0x7a, 0x97, 0x2c, 0x57, 0xd7, 0xbf, 0xfa, 0x1a, 0x0b,
    0x9e, 0x59, 0x17, 0x87, 0x60, 0x33, 0x6d, 0x02, 0x81, 0x81, 0x00, 0xdb,
    0x0a, 0xa8, 0x10, 0x0f, 0x10, 0x78, 0xaf, 0x3a, 0x07, 0x6d, 0x1a, 0x31,
    0x24, 0x1e, 0xc3, 0xc4, 0x51, 0x41, 0xed, 0xa0, 0xbe, 0xdd, 0x60, 0xe4,
    0xde, 0x67, 0x34, 0xd6, 0xe2, 0x43, 0x5e, 0xe3, 0x38, 0xf2, 0x61, 0x3a,
    0x3c, 0xda, 0xa3, 0x96, 0x11, 0x19, 0x75, 0x89, 0xa3, 0x89, 0xf5, 0xb4,
    0x3d, 0x7c, 0xe9, 0xff, 0x72, 0xd6, 0xef, 0xd8, 0x2c, 0x97, 0x28, 0xdb,
    0xa4, 0x25, 0x9d, 0x37, 0xf2, 0xf6, 0xfc, 0x11, 0x4d, 0xba, 0x7b, 0x4f,
    0x44, 0xa2, 0x2d, 0x8b, 0x57, 0x5c, 0xc0, 0x02, 0xe3, 0xc6, 0x7c, 0xce,
    0x6c, 0xae, 0xb7, 0x9c, 0xe0, 0x7b, 0x51, 0x1d, 0x38, 0x7c, 0xcc, 0x6b,
    0x78, 0x13, 0x15, 0x28, 0x16, 0x02, 0xf6, 0xc7, 0xaf, 0x11, 0x10, 0x05,
    0x79, 0xc9, 0xa4, 0xee, 0x55, 0x43, 0xfb, 0x3e, 0x0e, 0x82, 0x34, 0x7e,
    0x91, 0x18, 0x6e, 0x07, 0x53, 0x25, 0x0d, 0x02, 0x81, 0x81, 0x00, 0xd0,
    0x83, 0x0a, 0x48, 0xe0, 0x2e, 0x01, 0x8b, 0x93, 0xa0, 0xba, 0x1c, 0xc0,
    0xe7, 0x08, 0x6f, 0x3c, 0x9c, 0x04, 0xfd, 0xea, 0x89, 0x11, 0x3e, 0x8a,
    0x4f, 0x5b, 0x27, 0x7a, 0x84, 0x6e, 0x01, 0x9e, 0x7e, 0xaf, 0x55, 0xc8,
    0xe4, 0xe8, 0x4f, 0xaf, 0x84, 0x65, 0x5f, 0x85, 0x2b, 0x7d, 0x2a, 0x14,
    0x0b, 0x08, 0x77, 0x51, 0x8d, 0xae, 0x23, 0xff, 0xf2, 0xdb, 0x0d, 0xb6,
    0xb1, 0xc3, 0x2b, 0x6c, 0x9b, 0x3b, 0x02, 0x5c, 0x87, 0xa3, 0xa6, 0x27,
    0x2a, 0x50, 0x1b, 0xf0, 0xda, 0x0d, 0x35, 0x25, 0xc6, 0x43, 0xb7, 0x94,
    0x15, 0x98, 0xa8, 0xe2, 0xfd, 0x29, 0x56, 0x53, 0xce, 0x84, 0x57, 0x4a,
    0x1f, 0x20, 0x1a, 0x49, 0x10, 0x54, 0xcc, 0x9b, 0x95, 0x8d, 0x3f, 0x50,
    0xfe, 0x3d, 0x8d, 0x03, 0x9e, 0xf1, 0x98, 0x37, 0xaa, 0xc1, 0x00, 0x0c,
    0xb5, 0xa2, 0xf9, 0x95, 0xa3, 0x8e, 0x0b, 0x02, 0x81, 0x80, 0x08, 0x24,
    0x49, 0x42, 0xef, 0x8c, 0x69, 0x2f, 0xfa, 0x34, 0x34, 0x75, 0xf8, 0xc5,
    0xa2, 0xef, 0x1b, 0xe8, 0xf9, 0x4e, 0x5f, 0xdf, 0x38, 0x53, 0x55, 0xae,
    0x7e, 0x9f, 0x94, 0x2d, 0x2c, 0xdb, 0xe6, 0x0e, 0x43, 0xd4, 0x21, 0x5a,
    0x09, 0xb6, 0x72, 0xe9, 0x87, 0xcc, 0xba, 0xa4, 0xfd, 0x87, 0xc8, 0x7f,
    0x50, 0x99, 0x52, 0x09, 0x6e, 0xbb, 0xd3, 0x89, 0x34, 0xc5, 0x2c, 0x04,
    0xd9, 0xf1, 0x12, 0x17, 0x51, 0xde, 0xe4, 0xb5, 0xc2, 0xec, 0xba, 0x71,
    0x8e, 0xa5, 0xaa, 0xbc, 0x40, 0x92, 0x52, 0x89, 0x2c, 0xe3, 0x8e, 0xb8,
    0xb3, 0x75, 0xd7, 0xba, 0xf0, 0x5a, 0x7f, 0x7f, 0x8e, 0x03, 0xfb, 0x2a,
    0xa7, 0x6a, 0xed, 0xe6, 0x83, 0x8d, 0xb0, 0xb6, 0x6d, 0x27, 0xef, 0x4c,
    0x2b, 0x96, 0x99, 0xd5, 0x49, 0x85, 0x99, 0x34, 0xe8, 0xda, 0x12, 0xaa,
    0x4a, 0x02, 0x2c, 0xfb, 0x86, 0x31, 0x02, 0x81, 0x81, 0x00, 0x96, 0x2b,
    0xca, 0x5c, 0x72, 0x18, 0xb0, 0x44, 0x36, 0x2e, 0xab, 0xdb, 0xc9, 0x92,
    0x9b, 0x20, 0x82, 0x26, 0x5b, 0xf2, 0x03, 0xd8, 0x73, 0xf2, 0xf6, 0xe9,
    0xf0, 0x5c, 0x9e, 0x80, 0x82, 0x39, 0xe8, 0x4c, 0x95, 0x3a, 0xd3, 0x55,
    0x09, 0x7b, 0x5a, 0x8d, 0x9f, 0xf5, 0x0b, 0x94, 0x26, 0xb1, 0x07, 0x7e,
    0x6a, 0xba, 0x84, 0xa1, 0xe5, 0xa9, 0x47, 0xcd, 0x40, 0xb6, 0xbf, 0xbd,
    0x87, 0x32, 0xdf, 0x25, 0x6d, 0x7a, 0x65, 0xe9, 0xca, 0x92, 0xff, 0xe2,
    0x19, 0x90, 0x06, 0x07, 0x05, 0x3c, 0x21, 0xd8, 0x89, 0x2c, 0xce, 0x1a,
    0x3f, 0xb8, 0x62, 0xc2, 0xb1, 0xe2, 0xda, 0xb9, 0x01, 0xd7, 0x5c, 0x2a,
    0xce, 0x94, 0x1f, 0xcb, 0x03, 0x47, 0xd9, 0x45, 0xfc, 0x54, 0x7d, 0xa0,
    0x9d, 0xf3, 0xd1, 0x87, 0xc7, 0xb8, 0x39, 0x5f, 0x61, 0x61, 0x07, 0xc6,
    0x49, 0x7a, 0x37, 0xab, 0x73, 0xc1, 0x02, 0x81, 0x81, 0x00, 0x9b, 0x62,
    0x86, 0x1c, 0xfd, 0x9e, 0x32, 0xf0, 0x1e, 0x09, 0x49, 0xea, 0x5b, 0xb7,
    0x65, 0x0f, 0x4c, 0x44, 0xd6, 0x2b, 0x66, 0x95, 0x85, 0x13, 0xe7, 0x9a,
    0xea, 0xb5, 0xc7, 0x05, 0x33, 0xe6, 0x04, 0x9f, 0x08, 0x62, 0xd0, 0xf1,
    0x0f, 0x06, 0xe9, 0xc7, 0x72, 0x2a, 0x63, 0xae, 0x66, 0x9c, 0x84, 0xef,
    0x2a, 0x92, 0x5e, 0x58, 0xdc, 0x85, 0x73, 0xad, 0xcb, 0x28, 0x26, 0x5b,
    0x67, 0x9a, 0x81, 0x60, 0xdb, 0x6a, 0x51, 0x7e, 0x81, 0xbc, 0x0e, 0xe4,
    0xdb, 0x13, 0x2a, 0x6c, 0x95, 0x86, 0x99, 0x48, 0xdf, 0x00, 0x54, 0x29,
    0x68, 0xcb, 0x20, 0xaa, 0x9f, 0x0a, 0xe5, 0x8f, 0xd3, 0x15, 0x97, 0xc6,
    0xf3, 0xa2, 0xd8, 0x26, 0x05, 0xf0, 0x4e, 0x04, 0x25, 0x50, 0xe8, 0x19,
    0xa9, 0x93, 0xaf, 0xb0, 0x08, 0xb7, 0x7a, 0xcb, 0x53, 0x81, 0x7d, 0xe6,
    0x57, 0x01, 0x2f, 0x06, 0x26, 0x19};

namespace {

// Signing key test data in DER-encoded PKCS8 format.
const uint8_t kSigningKey[] = {
    0x30, 0x82, 0x01, 0x55, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
    0x01, 0x3f, 0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00,
    0xd9, 0xcd, 0xca, 0xcd, 0xc3, 0xea, 0xbe, 0x72, 0x79, 0x1c, 0x29, 0x37,
    0x39, 0x99, 0x1f, 0xd4, 0xb3, 0x0e, 0xf0, 0x7b, 0x78, 0x77, 0x0e, 0x05,
    0x3b, 0x65, 0x34, 0x12, 0x62, 0xaf, 0xa6, 0x8d, 0x33, 0xce, 0x78, 0xf8,
    0x47, 0x05, 0x1d, 0x98, 0xaa, 0x1b, 0x1f, 0x50, 0x05, 0x5b, 0x3c, 0x19,
    0x3f, 0x80, 0x83, 0x63, 0x63, 0x3a, 0xec, 0xcb, 0x2e, 0x90, 0x4f, 0xf5,
    0x26, 0x76, 0xf1, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x64,
    0x29, 0xc2, 0xd9, 0x6b, 0xfe, 0xf9, 0x84, 0x75, 0x73, 0xe0, 0xf4, 0x77,
    0xb5, 0x96, 0xb0, 0xdf, 0x83, 0xc0, 0x4e, 0x57, 0xf1, 0x10, 0x6e, 0x91,
    0x89, 0x12, 0x30, 0x5e, 0x57, 0xff, 0x14, 0x59, 0x5f, 0x18, 0x86, 0x4e,
    0x4b, 0x17, 0x56, 0xfc, 0x8d, 0x40, 0xdd, 0x74, 0x65, 0xd3, 0xff, 0x67,
    0x64, 0xcb, 0x9c, 0xb4, 0x14, 0x8a, 0x06, 0xb7, 0x13, 0x45, 0x94, 0x16,
    0x7d, 0x3f, 0xe1, 0x02, 0x21, 0x00, 0xf6, 0x0f, 0x31, 0x6d, 0x06, 0xcc,
    0x3b, 0xa0, 0x44, 0x1f, 0xf5, 0xc2, 0x45, 0x2b, 0x10, 0x6c, 0xf9, 0x6f,
    0x8f, 0x87, 0x3d, 0xc0, 0x3b, 0x55, 0x13, 0x37, 0x80, 0xcd, 0x9f, 0xe1,
    0xb7, 0xd9, 0x02, 0x21, 0x00, 0xe2, 0x9a, 0x5f, 0xbf, 0x95, 0x74, 0xb5,
    0x7a, 0x6a, 0xa6, 0x97, 0xbd, 0x75, 0x8c, 0x97, 0x18, 0x24, 0xd6, 0x09,
    0xcd, 0xdc, 0xb5, 0x94, 0xbf, 0xe2, 0x78, 0xaa, 0x20, 0x47, 0x9f, 0x68,
    0x5d, 0x02, 0x21, 0x00, 0xaf, 0x8f, 0x97, 0x8c, 0x5a, 0xd5, 0x4d, 0x95,
    0xc4, 0x05, 0xa9, 0xab, 0xba, 0xfe, 0x46, 0xf1, 0xf9, 0xe7, 0x07, 0x59,
    0x4f, 0x4d, 0xe1, 0x07, 0x8a, 0x76, 0x87, 0x88, 0x2f, 0x13, 0x35, 0xc1,
    0x02, 0x20, 0x24, 0xc3, 0xd9, 0x2f, 0x13, 0x47, 0x99, 0x3e, 0x20, 0x59,
    0xa1, 0x1a, 0xeb, 0x1c, 0x81, 0x53, 0x38, 0x7e, 0xc5, 0x9e, 0x71, 0xe5,
    0xc0, 0x19, 0x95, 0xdb, 0xef, 0xf6, 0x46, 0xc8, 0x95, 0x3d, 0x02, 0x21,
    0x00, 0xaa, 0xb1, 0xff, 0x8a, 0xa2, 0xb2, 0x2b, 0xef, 0x9a, 0x83, 0x3f,
    0xc5, 0xbc, 0xd4, 0x6a, 0x07, 0xe8, 0xc7, 0x0b, 0x2e, 0xd4, 0x0f, 0xf8,
    0x98, 0x68, 0xe1, 0x04, 0xa8, 0x92, 0xd0, 0x10, 0xaa,
};

// SHA256 signature of kSigningKey for "example.com" domain.
const uint8_t kSigningKeySignature[] = {
    0x54, 0x20, 0x93, 0x27, 0x2e, 0x7e, 0xae, 0xd5, 0xe5, 0x0f, 0x22, 0x56,
    0x09, 0x0b, 0x38, 0x40, 0x05, 0x0f, 0x25, 0x80, 0xbe, 0xd8, 0xe4, 0x9e,
    0xf0, 0x54, 0xca, 0xc8, 0x04, 0x72, 0x66, 0xcd, 0x1d, 0x6a, 0xb1, 0x04,
    0x00, 0x61, 0x19, 0xc4, 0xee, 0x2a, 0x59, 0xca, 0x65, 0xd3, 0x05, 0xd9,
    0x62, 0x87, 0x98, 0xa9, 0xb2, 0x2f, 0x06, 0xf7, 0x25, 0xcb, 0x66, 0xf4,
    0x17, 0xf6, 0x6f, 0x33, 0xfc, 0x0c, 0xd9, 0x4a, 0x06, 0xff, 0x82, 0xa4,
    0x44, 0x27, 0xba, 0xd0, 0x8a, 0xd0, 0x88, 0x06, 0x63, 0x15, 0x99, 0xdc,
    0x13, 0xb1, 0xf7, 0x86, 0x4a, 0xa7, 0xfb, 0x76, 0xd5, 0x27, 0xb9, 0x09,
    0x11, 0x6b, 0xe5, 0x09, 0x81, 0x33, 0x2f, 0x44, 0x14, 0x11, 0xfc, 0x24,
    0x42, 0xd4, 0x42, 0x50, 0x9b, 0x73, 0xd3, 0xa2, 0x1e, 0xba, 0xb2, 0x94,
    0x0f, 0xc7, 0x3e, 0xac, 0x9c, 0x34, 0xfa, 0x2b, 0x60, 0x22, 0xe3, 0x46,
    0xd7, 0x7c, 0x14, 0x9c, 0xd3, 0x08, 0xd5, 0x24, 0x5f, 0x72, 0x0a, 0xec,
    0x82, 0x10, 0x22, 0x58, 0xbd, 0x6c, 0x8f, 0x45, 0xae, 0xf9, 0x33, 0x68,
    0xe1, 0x16, 0x6e, 0x3a, 0x41, 0x3d, 0x84, 0x0a, 0xc0, 0xa0, 0xb4, 0x06,
    0x3a, 0xb5, 0x64, 0x16, 0x1f, 0x41, 0x19, 0x3b, 0x02, 0x28, 0xf7, 0x21,
    0x6c, 0x1e, 0x64, 0x9e, 0xa3, 0xa9, 0xf5, 0x33, 0x1c, 0x05, 0x28, 0xfc,
    0x6f, 0x2e, 0xb0, 0x70, 0xcd, 0xf8, 0x36, 0x33, 0xa3, 0xc6, 0x06, 0x7b,
    0x82, 0x56, 0xe4, 0x75, 0x3e, 0x1c, 0xb1, 0xf3, 0x60, 0xfa, 0x19, 0x66,
    0x8c, 0x78, 0xe8, 0x11, 0xa3, 0xc2, 0x30, 0xf4, 0x9b, 0x42, 0x90, 0xe1,
    0xc5, 0x0c, 0x4a, 0x97, 0xf2, 0xce, 0xc9, 0x08, 0xa1, 0xf9, 0xb2, 0x3c,
    0xf1, 0x30, 0x9c, 0x36, 0xa1, 0x00, 0xd7, 0xf3, 0xee, 0x42, 0x40, 0xbd,
    0xe4, 0x87, 0x95, 0x5d};

// SHA256 signature of kSigningKey for "gmail.com" domain when the testing
// verification key is used.
const uint8_t kSigningKeySignatureForChild[] = {
    0x09, 0xb9, 0x96, 0x69, 0x79, 0xa6, 0xd7, 0x3c, 0x27, 0xdc, 0x47, 0x2b,
    0x75, 0x85, 0x01, 0x2f, 0x75, 0xa5, 0x4d, 0xed, 0x1d, 0xde, 0x9e, 0xae,
    0xfd, 0x45, 0xbf, 0x5e, 0x25, 0xca, 0xe2, 0x0c, 0x77, 0x10, 0x7d, 0x51,
    0xa3, 0xea, 0x87, 0x78, 0x48, 0x14, 0xeb, 0xe3, 0x83, 0x0a, 0xce, 0xb3,
    0x1b, 0xfb, 0x96, 0xfa, 0x36, 0x11, 0xdf, 0x65, 0xa9, 0xd6, 0xaa, 0x00,
    0x54, 0x7c, 0x99, 0x28, 0x70, 0x7c, 0xf7, 0xdf, 0xa3, 0xb3, 0xc9, 0x0c,
    0xcf, 0x48, 0x3b, 0xac, 0x0b, 0x46, 0x7e, 0xd8, 0x3d, 0x6d, 0xe1, 0x65,
    0xc5, 0x67, 0x9a, 0xd8, 0xaf, 0x0c, 0x4b, 0x12, 0x65, 0x73, 0xff, 0xa6,
    0x85, 0xdb, 0xea, 0xe1, 0x37, 0x41, 0xb5, 0xc0, 0x21, 0x09, 0x6c, 0xf2,
    0x56, 0x0d, 0x39, 0x58, 0x54, 0x15, 0xd4, 0x38, 0xa5, 0xe7, 0x01, 0x2c,
    0x31, 0xf8, 0x95, 0x4e, 0xf5, 0x9a, 0xa2, 0x14, 0xbf, 0x06, 0xb1, 0x28,
    0xa2, 0x7a, 0x62, 0x2f, 0xd9, 0x60, 0xd3, 0x19, 0x50, 0xb2, 0x90, 0x4d,
    0xe2, 0x11, 0x19, 0x53, 0xb5, 0x55, 0xc1, 0xaf, 0x12, 0x23, 0x06, 0x6c,
    0x55, 0x24, 0x85, 0x20, 0x24, 0xe2, 0xf7, 0xb8, 0xac, 0x7e, 0x69, 0x47,
    0x1c, 0x0e, 0xc4, 0x3a, 0xb5, 0xc1, 0x89, 0x6c, 0x32, 0xcb, 0xca, 0x1d,
    0x97, 0x4b, 0x64, 0x69, 0x5f, 0x6c, 0xd0, 0xb0, 0xa8, 0x77, 0x00, 0xc6,
    0x6c, 0xdd, 0x93, 0x01, 0x2c, 0x57, 0xf3, 0xcf, 0xd6, 0xa1, 0xf5, 0xbe,
    0x95, 0x84, 0x8d, 0x44, 0xa2, 0xa6, 0x25, 0xdb, 0x5a, 0x49, 0x05, 0x18,
    0x59, 0x6c, 0x95, 0x99, 0x4f, 0xbb, 0x42, 0x7c, 0x42, 0x20, 0x32, 0xc1,
    0x11, 0x3e, 0xaa, 0x85, 0xe8, 0x78, 0x43, 0xe0, 0x88, 0xdd, 0x8b, 0x45,
    0xdc, 0xc7, 0xf7, 0xbb, 0x09, 0x3a, 0x54, 0xc0, 0x32, 0x79, 0x69, 0x2a,
    0x05, 0xcd, 0x42, 0x85};

// New signing key test data in DER-encoded PKCS8 format.
const uint8_t kNewSigningKey[] = {
    0x30, 0x82, 0x01, 0x54, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
    0x01, 0x3e, 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00,
    0x99, 0x98, 0x6b, 0x79, 0x5d, 0x38, 0x33, 0x79, 0x27, 0x0a, 0x2e, 0xb0,
    0x89, 0xba, 0xf8, 0xf6, 0x80, 0xde, 0xb0, 0x79, 0xf2, 0xd4, 0x6d, 0xf7,
    0x3c, 0xa3, 0x97, 0xf6, 0x4a, 0x3c, 0xa5, 0xcc, 0x40, 0x8a, 0xef, 0x59,
    0xaa, 0xc2, 0x82, 0x8f, 0xbc, 0x0d, 0x5b, 0x63, 0xc6, 0xaa, 0x72, 0xe2,
    0xf3, 0x57, 0xdd, 0x74, 0x00, 0xb0, 0x42, 0xd6, 0x27, 0xe7, 0x17, 0x61,
    0x0a, 0xdc, 0xc1, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x34,
    0xcf, 0xc9, 0xb4, 0x73, 0x2f, 0x0d, 0xd3, 0xcc, 0x6e, 0x9d, 0xdb, 0x29,
    0xa0, 0x56, 0x56, 0x3b, 0xbd, 0x56, 0x24, 0xb8, 0x2f, 0xfe, 0x97, 0x92,
    0x0c, 0x16, 0x06, 0x23, 0x44, 0x73, 0x25, 0x1d, 0x65, 0xf4, 0xda, 0x77,
    0xe7, 0x91, 0x2e, 0x91, 0x05, 0x10, 0xc1, 0x1b, 0x39, 0x5e, 0xb2, 0xf7,
    0xbd, 0x14, 0x19, 0xcb, 0x6b, 0xc3, 0xa9, 0xe8, 0x91, 0xf7, 0xa7, 0xa9,
    0x90, 0x08, 0x51, 0x02, 0x21, 0x00, 0xcc, 0x9e, 0x03, 0x54, 0x8f, 0x24,
    0xde, 0x90, 0x25, 0xec, 0x21, 0xaf, 0xe6, 0x27, 0x2a, 0x16, 0x42, 0x74,
    0xda, 0xf8, 0x84, 0xc4, 0x8c, 0x1e, 0x86, 0x12, 0x04, 0x5c, 0x17, 0x01,
    0xea, 0x9d, 0x02, 0x21, 0x00, 0xc0, 0x2a, 0x6c, 0xe9, 0xa1, 0x1a, 0x41,
    0x11, 0x94, 0x50, 0xf7, 0x1a, 0xd3, 0xbc, 0xf3, 0xa2, 0xf8, 0x46, 0xbc,
    0x26, 0x77, 0x78, 0xef, 0xc0, 0x54, 0xec, 0x22, 0x3f, 0x2c, 0x57, 0xe0,
    0xa3, 0x02, 0x20, 0x31, 0xf2, 0xc8, 0xa1, 0x55, 0xa8, 0x0c, 0x64, 0x67,
    0xbd, 0x72, 0xa3, 0xbb, 0xad, 0x07, 0xcb, 0x13, 0x41, 0xef, 0x4a, 0x07,
    0x2e, 0xeb, 0x7d, 0x70, 0x00, 0xe9, 0xeb, 0x88, 0xfa, 0x40, 0xc9, 0x02,
    0x20, 0x3a, 0xe0, 0xc4, 0xde, 0x10, 0x6e, 0x6a, 0xe1, 0x68, 0x00, 0x26,
    0xb6, 0x21, 0x8a, 0x13, 0x5c, 0x2b, 0x96, 0x00, 0xb0, 0x08, 0x8b, 0x15,
    0x6a, 0x68, 0x9a, 0xb1, 0x23, 0x8a, 0x02, 0xa2, 0xe1, 0x02, 0x21, 0x00,
    0xa3, 0xf2, 0x2d, 0x55, 0xc1, 0x6d, 0x40, 0xfa, 0x1d, 0xf7, 0xba, 0x86,
    0xef, 0x50, 0x98, 0xfc, 0xee, 0x09, 0xcc, 0xe7, 0x22, 0xb9, 0x4e, 0x80,
    0x32, 0x1a, 0x6b, 0xb3, 0x5f, 0x35, 0xbd, 0xf3,
};

// SHA256 signature of kNewSigningKey for "example.com" domain.
const uint8_t kNewSigningKeySignature[] = {
    0x66, 0xc0, 0x12, 0xf5, 0x80, 0xe8, 0x6a, 0xe1, 0x94, 0x37, 0xed, 0x9b,
    0xf7, 0x8b, 0x35, 0x05, 0x36, 0xad, 0xc8, 0x18, 0x2e, 0x0a, 0x28, 0x13,
    0x32, 0x6b, 0x97, 0xd7, 0x9b, 0x1b, 0xda, 0x28, 0xa0, 0x3b, 0x17, 0xd9,
    0x05, 0xe2, 0xd1, 0x02, 0x5f, 0x69, 0xc4, 0xf9, 0xb8, 0xeb, 0x0b, 0xc5,
    0xea, 0x5a, 0x67, 0x2d, 0xc0, 0x68, 0x12, 0x7f, 0xa6, 0x0b, 0xf3, 0x5d,
    0x39, 0x84, 0x3a, 0x47, 0xa5, 0x16, 0x0e, 0x74, 0x35, 0x36, 0xdb, 0xf9,
    0xef, 0xd1, 0x40, 0xb6, 0xd8, 0x89, 0xe9, 0x4c, 0xab, 0x26, 0xa3, 0x94,
    0x68, 0x7f, 0xc0, 0x0f, 0xf3, 0xe6, 0xd2, 0x55, 0x01, 0x3f, 0x45, 0x5f,
    0x48, 0x68, 0x49, 0xcb, 0x95, 0x4c, 0x00, 0x6c, 0x38, 0x95, 0x80, 0x89,
    0x29, 0xd5, 0xdc, 0x0b, 0xfc, 0x52, 0x25, 0x82, 0xb1, 0xa8, 0xe3, 0x36,
    0xd8, 0x0a, 0x82, 0xd7, 0x73, 0xd0, 0xcf, 0x4f, 0x29, 0xcc, 0x5f, 0x58,
    0x6a, 0x0c, 0x33, 0xb5, 0x55, 0x65, 0xd4, 0xbb, 0x30, 0x18, 0xc5, 0x53,
    0x6f, 0xf2, 0xa3, 0xd1, 0xff, 0x23, 0xb8, 0x5e, 0x3f, 0xe9, 0xc7, 0xe5,
    0x67, 0x4a, 0xfe, 0x94, 0x5a, 0xe8, 0x76, 0x81, 0xef, 0x4f, 0xed, 0xdf,
    0x3d, 0xdf, 0xd4, 0x52, 0x1e, 0x14, 0x29, 0xc6, 0x29, 0xe7, 0x6e, 0xd8,
    0xe4, 0xcb, 0xd1, 0xf1, 0x26, 0x6e, 0x43, 0xa1, 0x02, 0x26, 0xc5, 0x25,
    0x43, 0x9e, 0x7b, 0x5d, 0x72, 0x44, 0xd6, 0xe3, 0x36, 0x67, 0xfe, 0xfa,
    0x12, 0xb9, 0xc2, 0xe3, 0x37, 0x3a, 0x34, 0x87, 0xd3, 0xf1, 0x24, 0x60,
    0x11, 0xb7, 0xb1, 0x68, 0xcf, 0xa3, 0xfd, 0x0c, 0xce, 0x07, 0x9b, 0xf7,
    0xee, 0x37, 0xa2, 0xaf, 0x41, 0x5b, 0xa7, 0x71, 0x8a, 0xd1, 0x7d, 0xf6,
    0xd6, 0x58, 0xff, 0x48, 0xf3, 0xcd, 0x67, 0x2c, 0x3b, 0xbb, 0x7d, 0xef,
    0x6b, 0xa2, 0x5b, 0xf3};

// The public part of the key to be used by CloudPolicyValidator for
// checking the new public key data signature. This is replacement
// for baked in the code |verification_key_| used by the validator.
// Since we have the private part of this key, in kVerificationPrivateKey
// new signatures can be generated that will pass the checks from
// CloudPolicyValidator.
const uint8_t kVerificationPublicKey[] = {
    0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
    0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
    0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb2, 0x68, 0xc7,
    0xcd, 0xd1, 0xd5, 0xac, 0xe1, 0xb9, 0xfc, 0x97, 0xbd, 0x94, 0x5e, 0xef,
    0x1b, 0xf6, 0x0d, 0xea, 0x47, 0xc8, 0xb0, 0x8f, 0xa2, 0xb2, 0x17, 0xa3,
    0xd5, 0x3f, 0x1d, 0x40, 0x0c, 0x26, 0xa6, 0xf3, 0xc4, 0xb9, 0xc6, 0xbe,
    0x8c, 0x79, 0xe1, 0x92, 0x26, 0xd9, 0xae, 0x2d, 0xdb, 0x3f, 0xbb, 0x62,
    0xda, 0x1b, 0x28, 0x70, 0x1d, 0x60, 0x65, 0xb9, 0x70, 0x21, 0x0e, 0x57,
    0xad, 0x28, 0x52, 0x17, 0x74, 0xf2, 0x8d, 0x86, 0x86, 0x47, 0xad, 0xd5,
    0x8c, 0xfe, 0xb3, 0x71, 0x81, 0x9f, 0x74, 0x6b, 0x66, 0x4c, 0x32, 0x8d,
    0xb4, 0x45, 0x5a, 0xe1, 0x06, 0xc2, 0x45, 0xc1, 0xa5, 0xcd, 0x6d, 0x2d,
    0xb2, 0x43, 0x63, 0xd8, 0xaa, 0xb9, 0x1b, 0xa5, 0x53, 0x9b, 0xe7, 0x75,
    0xc0, 0x0d, 0x7c, 0xc8, 0xdc, 0x54, 0x4b, 0xde, 0xb6, 0x7b, 0x6e, 0x8f,
    0xfc, 0xfc, 0x39, 0xbd, 0x06, 0x32, 0xfc, 0x6f, 0x47, 0xab, 0x68, 0xab,
    0x66, 0x98, 0x50, 0xe0, 0x94, 0xfb, 0x7c, 0x15, 0x03, 0xf2, 0xa5, 0xd6,
    0x61, 0xa7, 0x70, 0x57, 0x49, 0x8f, 0x26, 0x75, 0x30, 0x99, 0xa3, 0xd7,
    0xa3, 0xd0, 0xb8, 0x26, 0xd9, 0xeb, 0x7f, 0xff, 0xc6, 0xa0, 0x62, 0x0b,
    0xc5, 0x38, 0xd6, 0x34, 0xc5, 0xaf, 0xb3, 0x93, 0x09, 0xaf, 0x37, 0xfc,
    0x98, 0x80, 0xf2, 0xf2, 0x5b, 0x5d, 0xce, 0xa5, 0x0e, 0xc7, 0x44, 0x31,
    0x87, 0x24, 0x00, 0xf7, 0xcd, 0xdd, 0xe1, 0xc8, 0xfe, 0xde, 0x46, 0x68,
    0x93, 0xe9, 0x3c, 0x1f, 0xad, 0x8a, 0xa6, 0xf5, 0x5f, 0x1f, 0x0c, 0x6a,
    0xa1, 0x1c, 0x39, 0xe1, 0xb5, 0x71, 0xa3, 0x4f, 0x2f, 0x62, 0x48, 0xcd,
    0x52, 0x65, 0x58, 0x7b, 0x84, 0x40, 0x31, 0x14, 0x4e, 0x01, 0x58, 0x4e,
    0x89, 0x9b, 0x3a, 0x04, 0x3e, 0x0f, 0x9d, 0x66, 0xf0, 0x97, 0x66, 0xcd,
    0x8f, 0x02, 0x03, 0x01, 0x00, 0x01};

// The signature for the new public key verification data corresponding
// to public_key = policy_signing_key, domain = kFakeDomain and
// new_public_key_version = kNewPublicKeyVersion blob that is signed with
// kVerificationPublicKey.
const uint8_t kPublicKeyVerificationDataSignature[] = {
    0x92, 0x70, 0xb0, 0x64, 0x44, 0x88, 0x9c, 0x3d, 0x51, 0x32, 0xc1, 0x62,
    0x1f, 0x74, 0xff, 0x3f, 0x6f, 0x1a, 0x6d, 0x56, 0x33, 0xbe, 0x4e, 0xd6,
    0x4e, 0xf0, 0x14, 0xd8, 0x21, 0xf5, 0x77, 0x89, 0x54, 0x56, 0x49, 0xbd,
    0xaf, 0x18, 0xc1, 0x0b, 0xd3, 0xbd, 0xe9, 0x2a, 0x01, 0xdf, 0x94, 0x87,
    0xab, 0x6b, 0xb8, 0xdb, 0x1e, 0x28, 0xaa, 0x62, 0xa6, 0x3e, 0x0e, 0x7b,
    0x9d, 0xc8, 0xe4, 0x54, 0x1f, 0x0e, 0xa8, 0xc6, 0xc6, 0x35, 0xd4, 0x13,
    0x78, 0xdd, 0x7e, 0xa3, 0xbf, 0xbb, 0x68, 0x4c, 0xaf, 0x36, 0x9e, 0x51,
    0x4e, 0xa8, 0x0e, 0xf7, 0x81, 0xad, 0x8f, 0x5d, 0xaf, 0x18, 0xe6, 0x5c,
    0x77, 0xdc, 0xda, 0xa7, 0x9a, 0x7f, 0x10, 0x60, 0x7a, 0x23, 0xba, 0xf8,
    0x0f, 0xc6, 0x12, 0xa6, 0xea, 0x82, 0xa1, 0x7b, 0x6a, 0xe0, 0x79, 0x4e,
    0x95, 0x40, 0xd5, 0x7f, 0x98, 0x3b, 0xc5, 0xa3, 0x15, 0xd6, 0xba, 0x74,
    0x8f, 0x22, 0x6a, 0x2b, 0x32, 0x7a, 0x8f, 0x3a, 0x25, 0xc4, 0x40, 0x7b,
    0x34, 0xe4, 0x40, 0xd5, 0x4a, 0xa5, 0x5f, 0xc2, 0x85, 0x53, 0x06, 0x9f,
    0xe7, 0x95, 0x95, 0x48, 0x0c, 0xff, 0xf7, 0x3f, 0x1c, 0xce, 0xd4, 0xcd,
    0x7a, 0xc7, 0x7d, 0x81, 0x19, 0x55, 0x1f, 0x26, 0x59, 0xf1, 0xa7, 0xea,
    0x20, 0x8d, 0x62, 0x51, 0xa6, 0x69, 0x79, 0xbe, 0xd7, 0x75, 0x52, 0xd9,
    0x83, 0xe3, 0xd8, 0x77, 0x69, 0x04, 0x27, 0xc0, 0xf5, 0x70, 0x8c, 0xf9,
    0xc7, 0x56, 0x66, 0xcc, 0x98, 0x43, 0x3f, 0x5e, 0xc6, 0x62, 0x37, 0x22,
    0xcc, 0x11, 0x96, 0x5c, 0xe8, 0x1f, 0x18, 0x69, 0x4f, 0x8f, 0xf1, 0x1d,
    0xbe, 0x35, 0x4f, 0xd8, 0x66, 0x30, 0x36, 0x83, 0xa3, 0x05, 0x53, 0xa0,
    0xe6, 0x8e, 0x42, 0xf1, 0xd9, 0x26, 0x1f, 0x90, 0x0e, 0xc8, 0x81, 0x75,
    0x23, 0x23, 0xde, 0xe1};

// The version of new public key for verification data
const int32_t kNewPublicKeyVersion = 1;

const char user_affiliation_id1[] = "id1";
const char user_affiliation_id2[] = "id2";

std::vector<uint8_t> ExportPublicKey(const crypto::RSAPrivateKey& key) {
  std::vector<uint8_t> public_key;
  CHECK(key.ExportPublicKey(&public_key));
  return public_key;
}

std::string ConvertPublicKeyToString(const std::vector<uint8_t>& public_key) {
  return std::string(reinterpret_cast<const char*>(public_key.data()),
                     public_key.size());
}

// Produces |key|'s signature over |data| and stores it in |signature|.
void SignData(const std::string& data,
              crypto::RSAPrivateKey* const key,
              std::string* const signature,
              em::PolicyFetchRequest::SignatureType signature_type) {
  crypto::SignatureCreator::HashAlgorithm algorithm;
  switch (signature_type) {
    case em::PolicyFetchRequest::SHA1_RSA:
      algorithm = crypto::SignatureCreator::SHA1;
      break;
    case em::PolicyFetchRequest::SHA256_RSA:
      algorithm = crypto::SignatureCreator::SHA256;
      break;
    default:
      // `em::PolicyFetchRequest::NONE` indicates unsigned blobs.
      // Crash is OK here.
      NOTREACHED();
  }

  std::unique_ptr<crypto::SignatureCreator> signature_creator(
      crypto::SignatureCreator::Create(key, algorithm));
  signature_creator->Update(reinterpret_cast<const uint8_t*>(data.c_str()),
                            data.size());
  std::vector<uint8_t> signature_bytes;
  CHECK(signature_creator->Final(&signature_bytes));
  signature->assign(reinterpret_cast<const char*>(signature_bytes.data()),
                    signature_bytes.size());
}

}  // namespace

// Constants used as dummy data for filling the PolicyData protobuf.
// LINT.IfChange
const GaiaId::Literal PolicyBuilder::kFakeGaiaId("0000111111");
const char PolicyBuilder::kFakeUsername[] = "username@example.com";
// LINT.ThenChange(/chrome/test/base/fake_gaia_mixin.cc)

const char PolicyBuilder::kFakeDeviceId[] = "device-id";
const char PolicyBuilder::kFakeDomain[] = "example.com";
const char PolicyBuilder::kFakeMachineName[] = "machine-name";
const char PolicyBuilder::kFakePolicyType[] = "policy type";
const int PolicyBuilder::kFakePublicKeyVersion = 17;
const int64_t PolicyBuilder::kFakeTimestamp = 365LL * 24 * 60 * 60 * 1000;
const char PolicyBuilder::kFakeToken[] = "token";
const char PolicyBuilder::kFakeServiceAccountIdentity[] = "robot4test@g.com";

PolicyBuilder::PolicyBuilder() {
  SetDefaultSigningKey();
  CreatePolicyData();
  policy_data_->set_policy_type(kFakePolicyType);
  policy_data_->set_timestamp(kFakeTimestamp);
  policy_data_->set_gaia_id(kFakeGaiaId.ToString());
  policy_data_->set_request_token(kFakeToken);
  policy_data_->set_machine_name(kFakeMachineName);
  policy_data_->set_public_key_version(kFakePublicKeyVersion);
  policy_data_->set_username(kFakeUsername);
  policy_data_->set_device_id(kFakeDeviceId);
  policy_data_->set_state(em::PolicyData::ACTIVE);
  policy_data_->set_service_account_identity(kFakeServiceAccountIdentity);
  policy_data_->set_cec_enabled(true);
  policy_data_->set_command_invalidation_topic("fake-topic");
  policy_data_->add_user_affiliation_ids(user_affiliation_id1);
  policy_data_->add_user_affiliation_ids(user_affiliation_id2);
}

PolicyBuilder::~PolicyBuilder() = default;

std::unique_ptr<crypto::RSAPrivateKey> PolicyBuilder::GetSigningKey() const {
  if (raw_signing_key_.empty())
    return nullptr;
  return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_signing_key_);
}

void PolicyBuilder::SetSigningKey(const crypto::RSAPrivateKey& key) {
  key.ExportPrivateKey(&raw_signing_key_);
}

void PolicyBuilder::SetDefaultSigningKey() {
  raw_signing_key_.assign(std::begin(kSigningKey), std::end(kSigningKey));
}

void PolicyBuilder::UnsetSigningKey() {
  raw_signing_key_.clear();
}

std::unique_ptr<crypto::RSAPrivateKey> PolicyBuilder::GetNewSigningKey() const {
  if (raw_new_signing_key_.empty())
    return nullptr;
  return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_new_signing_key_);
}

void PolicyBuilder::SetDefaultNewSigningKey() {
  raw_new_signing_key_.assign(std::begin(kNewSigningKey),
                              std::end(kNewSigningKey));
  raw_new_signing_key_signature_ = GetTestOtherSigningKeySignature();
}

void PolicyBuilder::UnsetNewSigningKey() {
  raw_new_signing_key_.clear();
  raw_new_signing_key_signature_.clear();
}

void PolicyBuilder::SetDefaultInitialSigningKey() {
  raw_new_signing_key_.assign(std::begin(kSigningKey), std::end(kSigningKey));
  raw_new_signing_key_signature_ = GetTestSigningKeySignature();
  UnsetSigningKey();
}

void PolicyBuilder::Build() {
  // Start with a clean state.
  policy_.clear_policy_data();
  policy_.clear_policy_data_signature();

  if (!policy_data_) {
    return;
  }

  // Serialize the policy data.
  CHECK(policy_data_->SerializeToString(policy_.mutable_policy_data()));

  // Signature type of `NONE` indicates an unsigned blob.
  if (signature_type_ == em::PolicyFetchRequest::NONE) {
    return;
  }

  // Rotate/install keys.
  std::unique_ptr<crypto::RSAPrivateKey> new_signing_key = GetNewSigningKey();
  std::unique_ptr<crypto::RSAPrivateKey> current_signing_key = GetSigningKey();
  crypto::RSAPrivateKey* key_to_sign_policy_data_with = nullptr;
  if (new_signing_key) {
    // Add the new public key.
    policy_.set_new_public_key(
        ConvertPublicKeyToString(ExportPublicKey(*new_signing_key)));
    policy_.set_new_public_key_verification_signature_deprecated(
        raw_new_signing_key_signature_);

    // Add the new public key verification data.
    em::PublicKeyVerificationData new_signing_key_verification_data;

    // Need to set as public key the key that will be used to validate the
    // policy. So, it's the new public key.
    new_signing_key_verification_data.set_new_public_key(
        ConvertPublicKeyToString(ExportPublicKey(*new_signing_key)));
    new_signing_key_verification_data.set_domain(kFakeDomain);
    new_signing_key_verification_data.set_new_public_key_version(
        kNewPublicKeyVersion);
    std::string new_signing_key_verification_data_as_string;
    CHECK(new_signing_key_verification_data.SerializeToString(
        &new_signing_key_verification_data_as_string));

    // Note that protobuf serialization doesn't guarantee the same output,
    // but the alternative of putting a hard-coded string here will make
    // the code less clear to read. So, we prefer to use this option with
    // the risk that in the future the signature given by this file will
    // fail.
    policy_.set_new_public_key_verification_data(
        new_signing_key_verification_data_as_string);
    std::string new_signing_key_verification_data_signature =
        GetPublicKeyVerificationDataSignature();
    policy_.set_new_public_key_verification_data_signature(
        new_signing_key_verification_data_signature);

    // The new public key must be signed by the current key in the event of key
    // rotation.
    if (current_signing_key) {
      SignData(policy_.new_public_key(), current_signing_key.get(),
               policy_.mutable_new_public_key_signature(), signature_type_);
    }

    key_to_sign_policy_data_with = new_signing_key.get();
  } else {
    // No new signing key, so clear the old public key (this allows us to
    // reuse the same PolicyBuilder to build multiple policy blobs).
    policy_.clear_new_public_key();
    policy_.clear_new_public_key_verification_signature_deprecated();
    policy_.clear_new_public_key_signature();
    policy_.clear_new_public_key_verification_data();
    policy_.clear_new_public_key_verification_data_signature();

    if (current_signing_key) {
      key_to_sign_policy_data_with = current_signing_key.get();
    }
  }

  // Sign if possible.
  if (key_to_sign_policy_data_with) {
    SignData(policy_.policy_data(), key_to_sign_policy_data_with,
             policy_.mutable_policy_data_signature(), signature_type_);

    // Generate signatures if applicable.
    policy_.set_policy_data_signature_type(signature_type_);
  } else {
    policy_data_->clear_public_key_version();
  }

  return;
}

std::string PolicyBuilder::GetBlob() const {
  return policy_.SerializeAsString();
}

std::unique_ptr<em::PolicyFetchResponse> PolicyBuilder::GetCopy() const {
  return std::make_unique<em::PolicyFetchResponse>(policy_);
}

// static
std::unique_ptr<crypto::RSAPrivateKey> PolicyBuilder::CreateTestSigningKey() {
  std::vector<uint8_t> raw_signing_key(std::begin(kSigningKey),
                                       std::end(kSigningKey));
  return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_signing_key);
}

// static
std::unique_ptr<crypto::RSAPrivateKey>
PolicyBuilder::CreateTestOtherSigningKey() {
  std::vector<uint8_t> raw_new_signing_key(std::begin(kNewSigningKey),
                                           std::end(kNewSigningKey));
  return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(raw_new_signing_key);
}

// static
std::string PolicyBuilder::GetEncodedPolicyVerificationKey() {
  return base::Base64Encode(
      std::string(reinterpret_cast<const char*>(kVerificationPublicKey),
                  std::size(kVerificationPublicKey)));
}

// static
std::string PolicyBuilder::GetPublicKeyVerificationDataSignature() {
  return std::string(
      reinterpret_cast<const char*>(kPublicKeyVerificationDataSignature),
      std::size(kPublicKeyVerificationDataSignature));
}

// static
std::string PolicyBuilder::GetTestSigningKeySignature() {
  return std::string(reinterpret_cast<const char*>(kSigningKeySignature),
                     std::size(kSigningKeySignature));
}

std::string PolicyBuilder::GetTestSigningKeySignatureForChild() {
  return std::string(
      reinterpret_cast<const char*>(kSigningKeySignatureForChild),
      std::size(kSigningKeySignatureForChild));
}

// static
std::string PolicyBuilder::GetTestOtherSigningKeySignature() {
  return std::string(reinterpret_cast<const char*>(kNewSigningKeySignature),
                     std::size(kNewSigningKeySignature));
}

std::vector<uint8_t> PolicyBuilder::GetPublicSigningKey() const {
  std::unique_ptr<crypto::RSAPrivateKey> key = GetSigningKey();
  if (!key)
    return std::vector<uint8_t>();
  return ExportPublicKey(*key);
}

std::vector<uint8_t> PolicyBuilder::GetPublicNewSigningKey() const {
  std::unique_ptr<crypto::RSAPrivateKey> key = GetNewSigningKey();
  if (!key)
    return std::vector<uint8_t>();
  return ExportPublicKey(*key);
}

// static
std::vector<uint8_t> PolicyBuilder::GetPublicTestKey() {
  return ExportPublicKey(*CreateTestSigningKey());
}

// static
std::vector<uint8_t> PolicyBuilder::GetPublicTestOtherKey() {
  return ExportPublicKey(*CreateTestOtherSigningKey());
}

std::string PolicyBuilder::GetPublicSigningKeyAsString() const {
  return ConvertPublicKeyToString(GetPublicSigningKey());
}

std::string PolicyBuilder::GetPublicNewSigningKeyAsString() const {
  return ConvertPublicKeyToString(GetPublicNewSigningKey());
}

// static
std::string PolicyBuilder::GetPublicTestKeyAsString() {
  return ConvertPublicKeyToString(GetPublicTestKey());
}

// static
std::string PolicyBuilder::GetPublicTestOtherKeyAsString() {
  return ConvertPublicKeyToString(GetPublicTestOtherKey());
}

// static
std::vector<std::string> PolicyBuilder::GetUserAffiliationIds() {
  return {user_affiliation_id1, user_affiliation_id2};
}

// static
AccountId PolicyBuilder::GetFakeAccountIdForTesting() {
  return AccountId::FromUserEmailGaiaId(kFakeUsername, kFakeGaiaId);
}

void PolicyBuilder::SetSignatureType(
    em::PolicyFetchRequest::SignatureType signature_type) {
  signature_type_ = signature_type;
}

template <>
TypedPolicyBuilder<em::CloudPolicySettings>::TypedPolicyBuilder()
    : payload_(new em::CloudPolicySettings()) {
  policy_data().set_policy_type(dm_protocol::kChromeUserPolicyType);
}

// Have the instantiation compiled into the module.
template class TypedPolicyBuilder<em::CloudPolicySettings>;

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
template <>
TypedPolicyBuilder<em::ExternalPolicyData>::TypedPolicyBuilder() {
  CreatePayload();
  policy_data().set_policy_type(dm_protocol::kChromeExtensionPolicyType);
}

template class TypedPolicyBuilder<em::ExternalPolicyData>;
#endif

#if BUILDFLAG(IS_CHROMEOS)
StringPolicyBuilder::StringPolicyBuilder() = default;

void StringPolicyBuilder::Build() {
  policy_data().set_policy_value(payload_);
  PolicyBuilder::Build();
}
#endif

}  // namespace policy