• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.keystore.cts;
18 
19 import android.security.KeyStoreParameter;
20 import android.test.AndroidTestCase;
21 
22 import java.io.ByteArrayInputStream;
23 import java.io.ByteArrayOutputStream;
24 import java.io.OutputStream;
25 import java.security.Key;
26 import java.security.KeyFactory;
27 import java.security.KeyStore;
28 import java.security.KeyStore.Entry;
29 import java.security.KeyStore.PrivateKeyEntry;
30 import java.security.KeyStore.TrustedCertificateEntry;
31 import java.security.KeyStoreException;
32 import java.security.PrivateKey;
33 import java.security.PublicKey;
34 import java.security.cert.Certificate;
35 import java.security.cert.CertificateFactory;
36 import java.security.interfaces.DSAPrivateKey;
37 import java.security.interfaces.DSAPublicKey;
38 import java.security.interfaces.ECPrivateKey;
39 import java.security.interfaces.ECPublicKey;
40 import java.security.interfaces.RSAPrivateKey;
41 import java.security.spec.PKCS8EncodedKeySpec;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.Collection;
45 import java.util.Date;
46 import java.util.Enumeration;
47 import java.util.HashSet;
48 import java.util.Iterator;
49 import java.util.Set;
50 
51 import javax.crypto.Cipher;
52 import javax.crypto.SecretKey;
53 import javax.crypto.spec.SecretKeySpec;
54 
55 public class AndroidKeyStoreTest extends AndroidTestCase {
56     private KeyStore mKeyStore;
57 
58     private static final String TEST_ALIAS_1 = "test1";
59 
60     private static final String TEST_ALIAS_2 = "test2";
61 
62     private static final String TEST_ALIAS_3 = "test3";
63 
64     /*
65      * The keys and certificates below are generated with:
66      *
67      * openssl req -new -x509 -days 3650 -extensions v3_ca -keyout cakey.pem -out cacert.pem
68      * openssl req -newkey rsa:1024 -keyout userkey.pem -nodes -days 3650 -out userkey.req
69      * mkdir -p demoCA/newcerts
70      * touch demoCA/index.txt
71      * echo "01" > demoCA/serial
72      * openssl ca -out usercert.pem -in userkey.req -cert cacert.pem -keyfile cakey.pem -days 3650
73      */
74 
75     /**
76      * Generated from above and converted with:
77      *
78      * openssl x509 -outform d -in cacert.pem | xxd -i | sed 's/0x/(byte) 0x/g'
79      */
80     private static final byte[] FAKE_RSA_CA_1 = {
81             (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0xce, (byte) 0x30, (byte) 0x82,
82             (byte) 0x02, (byte) 0x37, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01,
83             (byte) 0x02, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0xe1, (byte) 0x6a,
84             (byte) 0xa2, (byte) 0xf4, (byte) 0x2e, (byte) 0x55, (byte) 0x48, (byte) 0x0a,
85             (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86,
86             (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01,
87             (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x30, (byte) 0x4f, (byte) 0x31,
88             (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55,
89             (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x55, (byte) 0x53,
90             (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03,
91             (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x13, (byte) 0x02, (byte) 0x43,
92             (byte) 0x41, (byte) 0x31, (byte) 0x16, (byte) 0x30, (byte) 0x14, (byte) 0x06,
93             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x07, (byte) 0x13, (byte) 0x0d,
94             (byte) 0x4d, (byte) 0x6f, (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x61,
95             (byte) 0x69, (byte) 0x6e, (byte) 0x20, (byte) 0x56, (byte) 0x69, (byte) 0x65,
96             (byte) 0x77, (byte) 0x31, (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0x06,
97             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x13, (byte) 0x12,
98             (byte) 0x41, (byte) 0x6e, (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69,
99             (byte) 0x64, (byte) 0x20, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74,
100             (byte) 0x20, (byte) 0x43, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x73,
101             (byte) 0x30, (byte) 0x1e, (byte) 0x17, (byte) 0x0d, (byte) 0x31, (byte) 0x32,
102             (byte) 0x30, (byte) 0x38, (byte) 0x31, (byte) 0x34, (byte) 0x31, (byte) 0x36,
103             (byte) 0x35, (byte) 0x35, (byte) 0x34, (byte) 0x34, (byte) 0x5a, (byte) 0x17,
104             (byte) 0x0d, (byte) 0x32, (byte) 0x32, (byte) 0x30, (byte) 0x38, (byte) 0x31,
105             (byte) 0x32, (byte) 0x31, (byte) 0x36, (byte) 0x35, (byte) 0x35, (byte) 0x34,
106             (byte) 0x34, (byte) 0x5a, (byte) 0x30, (byte) 0x4f, (byte) 0x31, (byte) 0x0b,
107             (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
108             (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x55, (byte) 0x53, (byte) 0x31,
109             (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55,
110             (byte) 0x04, (byte) 0x08, (byte) 0x13, (byte) 0x02, (byte) 0x43, (byte) 0x41,
111             (byte) 0x31, (byte) 0x16, (byte) 0x30, (byte) 0x14, (byte) 0x06, (byte) 0x03,
112             (byte) 0x55, (byte) 0x04, (byte) 0x07, (byte) 0x13, (byte) 0x0d, (byte) 0x4d,
113             (byte) 0x6f, (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x61, (byte) 0x69,
114             (byte) 0x6e, (byte) 0x20, (byte) 0x56, (byte) 0x69, (byte) 0x65, (byte) 0x77,
115             (byte) 0x31, (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0x06, (byte) 0x03,
116             (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x13, (byte) 0x12, (byte) 0x41,
117             (byte) 0x6e, (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64,
118             (byte) 0x20, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20,
119             (byte) 0x43, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x30,
120             (byte) 0x81, (byte) 0x9f, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09,
121             (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d,
122             (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x03,
123             (byte) 0x81, (byte) 0x8d, (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0x89,
124             (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xa3, (byte) 0x72,
125             (byte) 0xab, (byte) 0xd0, (byte) 0xe4, (byte) 0xad, (byte) 0x2f, (byte) 0xe7,
126             (byte) 0xe2, (byte) 0x79, (byte) 0x07, (byte) 0x36, (byte) 0x3d, (byte) 0x0c,
127             (byte) 0x8d, (byte) 0x42, (byte) 0x9a, (byte) 0x0a, (byte) 0x33, (byte) 0x64,
128             (byte) 0xb3, (byte) 0xcd, (byte) 0xb2, (byte) 0xd7, (byte) 0x3a, (byte) 0x42,
129             (byte) 0x06, (byte) 0x77, (byte) 0x45, (byte) 0x29, (byte) 0xe9, (byte) 0xcb,
130             (byte) 0xb7, (byte) 0x4a, (byte) 0xd6, (byte) 0xee, (byte) 0xad, (byte) 0x01,
131             (byte) 0x91, (byte) 0x9b, (byte) 0x0c, (byte) 0x59, (byte) 0xa1, (byte) 0x03,
132             (byte) 0xfa, (byte) 0xf0, (byte) 0x5a, (byte) 0x7c, (byte) 0x4f, (byte) 0xf7,
133             (byte) 0x8d, (byte) 0x36, (byte) 0x0f, (byte) 0x1f, (byte) 0x45, (byte) 0x7d,
134             (byte) 0x1b, (byte) 0x31, (byte) 0xa1, (byte) 0x35, (byte) 0x0b, (byte) 0x00,
135             (byte) 0xed, (byte) 0x7a, (byte) 0xb6, (byte) 0xc8, (byte) 0x4e, (byte) 0xa9,
136             (byte) 0x86, (byte) 0x4c, (byte) 0x7b, (byte) 0x99, (byte) 0x57, (byte) 0x41,
137             (byte) 0x12, (byte) 0xef, (byte) 0x6b, (byte) 0xbc, (byte) 0x3d, (byte) 0x60,
138             (byte) 0xf2, (byte) 0x99, (byte) 0x1a, (byte) 0xcd, (byte) 0xed, (byte) 0x56,
139             (byte) 0xa4, (byte) 0xe5, (byte) 0x36, (byte) 0x9f, (byte) 0x24, (byte) 0x1f,
140             (byte) 0xdc, (byte) 0x89, (byte) 0x40, (byte) 0xc8, (byte) 0x99, (byte) 0x92,
141             (byte) 0xab, (byte) 0x4a, (byte) 0xb5, (byte) 0x61, (byte) 0x45, (byte) 0x62,
142             (byte) 0xff, (byte) 0xa3, (byte) 0x45, (byte) 0x65, (byte) 0xaf, (byte) 0xf6,
143             (byte) 0x27, (byte) 0x30, (byte) 0x51, (byte) 0x0e, (byte) 0x0e, (byte) 0xeb,
144             (byte) 0x79, (byte) 0x0c, (byte) 0xbe, (byte) 0xb3, (byte) 0x0a, (byte) 0x6f,
145             (byte) 0x29, (byte) 0x06, (byte) 0xdc, (byte) 0x2f, (byte) 0x6b, (byte) 0x51,
146             (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xa3,
147             (byte) 0x81, (byte) 0xb1, (byte) 0x30, (byte) 0x81, (byte) 0xae, (byte) 0x30,
148             (byte) 0x1d, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e,
149             (byte) 0x04, (byte) 0x16, (byte) 0x04, (byte) 0x14, (byte) 0x33, (byte) 0x05,
150             (byte) 0xee, (byte) 0xfe, (byte) 0x6f, (byte) 0x60, (byte) 0xc7, (byte) 0xf9,
151             (byte) 0xa9, (byte) 0xd2, (byte) 0x73, (byte) 0x5c, (byte) 0x8f, (byte) 0x6d,
152             (byte) 0xa2, (byte) 0x2f, (byte) 0x97, (byte) 0x8e, (byte) 0x5d, (byte) 0x51,
153             (byte) 0x30, (byte) 0x7f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d,
154             (byte) 0x23, (byte) 0x04, (byte) 0x78, (byte) 0x30, (byte) 0x76, (byte) 0x80,
155             (byte) 0x14, (byte) 0x33, (byte) 0x05, (byte) 0xee, (byte) 0xfe, (byte) 0x6f,
156             (byte) 0x60, (byte) 0xc7, (byte) 0xf9, (byte) 0xa9, (byte) 0xd2, (byte) 0x73,
157             (byte) 0x5c, (byte) 0x8f, (byte) 0x6d, (byte) 0xa2, (byte) 0x2f, (byte) 0x97,
158             (byte) 0x8e, (byte) 0x5d, (byte) 0x51, (byte) 0xa1, (byte) 0x53, (byte) 0xa4,
159             (byte) 0x51, (byte) 0x30, (byte) 0x4f, (byte) 0x31, (byte) 0x0b, (byte) 0x30,
160             (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06,
161             (byte) 0x13, (byte) 0x02, (byte) 0x55, (byte) 0x53, (byte) 0x31, (byte) 0x0b,
162             (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
163             (byte) 0x08, (byte) 0x13, (byte) 0x02, (byte) 0x43, (byte) 0x41, (byte) 0x31,
164             (byte) 0x16, (byte) 0x30, (byte) 0x14, (byte) 0x06, (byte) 0x03, (byte) 0x55,
165             (byte) 0x04, (byte) 0x07, (byte) 0x13, (byte) 0x0d, (byte) 0x4d, (byte) 0x6f,
166             (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x61, (byte) 0x69, (byte) 0x6e,
167             (byte) 0x20, (byte) 0x56, (byte) 0x69, (byte) 0x65, (byte) 0x77, (byte) 0x31,
168             (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0x06, (byte) 0x03, (byte) 0x55,
169             (byte) 0x04, (byte) 0x0a, (byte) 0x13, (byte) 0x12, (byte) 0x41, (byte) 0x6e,
170             (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x20,
171             (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x43,
172             (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x82, (byte) 0x09,
173             (byte) 0x00, (byte) 0xe1, (byte) 0x6a, (byte) 0xa2, (byte) 0xf4, (byte) 0x2e,
174             (byte) 0x55, (byte) 0x48, (byte) 0x0a, (byte) 0x30, (byte) 0x0c, (byte) 0x06,
175             (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13, (byte) 0x04, (byte) 0x05,
176             (byte) 0x30, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x30,
177             (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48,
178             (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05,
179             (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0x81, (byte) 0x00,
180             (byte) 0x8c, (byte) 0x30, (byte) 0x42, (byte) 0xfa, (byte) 0xeb, (byte) 0x1a,
181             (byte) 0x26, (byte) 0xeb, (byte) 0xda, (byte) 0x56, (byte) 0x32, (byte) 0xf2,
182             (byte) 0x9d, (byte) 0xa5, (byte) 0x24, (byte) 0xd8, (byte) 0x3a, (byte) 0xda,
183             (byte) 0x30, (byte) 0xa6, (byte) 0x8b, (byte) 0x46, (byte) 0xfe, (byte) 0xfe,
184             (byte) 0xdb, (byte) 0xf1, (byte) 0xe6, (byte) 0xe1, (byte) 0x7c, (byte) 0x1b,
185             (byte) 0xe7, (byte) 0x77, (byte) 0x00, (byte) 0xa1, (byte) 0x1c, (byte) 0x19,
186             (byte) 0x17, (byte) 0x73, (byte) 0xb0, (byte) 0xf0, (byte) 0x9d, (byte) 0xf3,
187             (byte) 0x4f, (byte) 0xb6, (byte) 0xbc, (byte) 0xc7, (byte) 0x47, (byte) 0x85,
188             (byte) 0x2a, (byte) 0x4a, (byte) 0xa1, (byte) 0xa5, (byte) 0x58, (byte) 0xf5,
189             (byte) 0xc5, (byte) 0x1a, (byte) 0x51, (byte) 0xb1, (byte) 0x04, (byte) 0x80,
190             (byte) 0xee, (byte) 0x3a, (byte) 0xec, (byte) 0x2f, (byte) 0xe1, (byte) 0xfd,
191             (byte) 0x58, (byte) 0xeb, (byte) 0xed, (byte) 0x82, (byte) 0x9e, (byte) 0x38,
192             (byte) 0xa3, (byte) 0x24, (byte) 0x75, (byte) 0xf7, (byte) 0x3e, (byte) 0xc2,
193             (byte) 0xc5, (byte) 0x27, (byte) 0xeb, (byte) 0x6f, (byte) 0x7b, (byte) 0x50,
194             (byte) 0xda, (byte) 0x43, (byte) 0xdc, (byte) 0x3b, (byte) 0x0b, (byte) 0x6f,
195             (byte) 0x78, (byte) 0x8f, (byte) 0xb0, (byte) 0x66, (byte) 0xe1, (byte) 0x12,
196             (byte) 0x87, (byte) 0x5f, (byte) 0x97, (byte) 0x7b, (byte) 0xca, (byte) 0x14,
197             (byte) 0x79, (byte) 0xf7, (byte) 0xe8, (byte) 0x6c, (byte) 0x72, (byte) 0xdb,
198             (byte) 0x91, (byte) 0x65, (byte) 0x17, (byte) 0x54, (byte) 0xe0, (byte) 0x74,
199             (byte) 0x1d, (byte) 0xac, (byte) 0x47, (byte) 0x04, (byte) 0x12, (byte) 0xe0,
200             (byte) 0xc3, (byte) 0x66, (byte) 0x19, (byte) 0x05, (byte) 0x2e, (byte) 0x7e,
201             (byte) 0xf1, (byte) 0x61
202     };
203 
204     /**
205      * Generated from above and converted with:
206      *
207      * openssl pkcs8 -topk8 -outform d -in userkey.pem -nocrypt | xxd -i | sed 's/0x/(byte) 0x/g'
208      */
209     private static final byte[] FAKE_RSA_KEY_1 = new byte[] {
210             (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x78, (byte) 0x02, (byte) 0x01,
211             (byte) 0x00, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a,
212             (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01,
213             (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x82,
214             (byte) 0x02, (byte) 0x62, (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x5e,
215             (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81,
216             (byte) 0x00, (byte) 0xce, (byte) 0x29, (byte) 0xeb, (byte) 0xf6, (byte) 0x5b,
217             (byte) 0x25, (byte) 0xdc, (byte) 0xa1, (byte) 0xa6, (byte) 0x2c, (byte) 0x66,
218             (byte) 0xcb, (byte) 0x20, (byte) 0x90, (byte) 0x27, (byte) 0x86, (byte) 0x8a,
219             (byte) 0x44, (byte) 0x71, (byte) 0x50, (byte) 0xda, (byte) 0xd3, (byte) 0x02,
220             (byte) 0x77, (byte) 0x55, (byte) 0xe9, (byte) 0xe8, (byte) 0x08, (byte) 0xf3,
221             (byte) 0x36, (byte) 0x9a, (byte) 0xae, (byte) 0xab, (byte) 0x04, (byte) 0x6d,
222             (byte) 0x00, (byte) 0x99, (byte) 0xbf, (byte) 0x7d, (byte) 0x0f, (byte) 0x67,
223             (byte) 0x8b, (byte) 0x1d, (byte) 0xd4, (byte) 0x2b, (byte) 0x7c, (byte) 0xcb,
224             (byte) 0xcd, (byte) 0x33, (byte) 0xc7, (byte) 0x84, (byte) 0x30, (byte) 0xe2,
225             (byte) 0x45, (byte) 0x21, (byte) 0xb3, (byte) 0x75, (byte) 0xf5, (byte) 0x79,
226             (byte) 0x02, (byte) 0xda, (byte) 0x50, (byte) 0xa3, (byte) 0x8b, (byte) 0xce,
227             (byte) 0xc3, (byte) 0x8e, (byte) 0x0f, (byte) 0x25, (byte) 0xeb, (byte) 0x08,
228             (byte) 0x2c, (byte) 0xdd, (byte) 0x1c, (byte) 0xcf, (byte) 0xff, (byte) 0x3b,
229             (byte) 0xde, (byte) 0xb6, (byte) 0xaa, (byte) 0x2a, (byte) 0xa9, (byte) 0xc4,
230             (byte) 0x8a, (byte) 0x24, (byte) 0x24, (byte) 0xe6, (byte) 0x29, (byte) 0x0d,
231             (byte) 0x98, (byte) 0x4c, (byte) 0x32, (byte) 0xa1, (byte) 0x7b, (byte) 0x23,
232             (byte) 0x2b, (byte) 0x42, (byte) 0x30, (byte) 0xee, (byte) 0x78, (byte) 0x08,
233             (byte) 0x47, (byte) 0xad, (byte) 0xf2, (byte) 0x96, (byte) 0xd5, (byte) 0xf1,
234             (byte) 0x62, (byte) 0x42, (byte) 0x2d, (byte) 0x35, (byte) 0x19, (byte) 0xb4,
235             (byte) 0x3c, (byte) 0xc9, (byte) 0xc3, (byte) 0x5f, (byte) 0x03, (byte) 0x16,
236             (byte) 0x3a, (byte) 0x23, (byte) 0xac, (byte) 0xcb, (byte) 0xce, (byte) 0x9e,
237             (byte) 0x51, (byte) 0x2e, (byte) 0x6d, (byte) 0x02, (byte) 0x03, (byte) 0x01,
238             (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x16,
239             (byte) 0x59, (byte) 0xc3, (byte) 0x24, (byte) 0x1d, (byte) 0x33, (byte) 0x98,
240             (byte) 0x9c, (byte) 0xc9, (byte) 0xc8, (byte) 0x2c, (byte) 0x88, (byte) 0xbf,
241             (byte) 0x0a, (byte) 0x01, (byte) 0xce, (byte) 0xfb, (byte) 0x34, (byte) 0x7a,
242             (byte) 0x58, (byte) 0x7a, (byte) 0xb0, (byte) 0xbf, (byte) 0xa6, (byte) 0xb2,
243             (byte) 0x60, (byte) 0xbe, (byte) 0x70, (byte) 0x21, (byte) 0xf5, (byte) 0xfc,
244             (byte) 0x85, (byte) 0x0d, (byte) 0x33, (byte) 0x58, (byte) 0xa1, (byte) 0xe5,
245             (byte) 0x09, (byte) 0x36, (byte) 0x84, (byte) 0xb2, (byte) 0x04, (byte) 0x0a,
246             (byte) 0x02, (byte) 0xd3, (byte) 0x88, (byte) 0x1f, (byte) 0x0c, (byte) 0x2b,
247             (byte) 0x1d, (byte) 0xe9, (byte) 0x3d, (byte) 0xe7, (byte) 0x79, (byte) 0xf9,
248             (byte) 0x32, (byte) 0x5c, (byte) 0x8a, (byte) 0x75, (byte) 0x49, (byte) 0x12,
249             (byte) 0xe4, (byte) 0x05, (byte) 0x26, (byte) 0xd4, (byte) 0x2e, (byte) 0x9e,
250             (byte) 0x1f, (byte) 0xcc, (byte) 0x54, (byte) 0xad, (byte) 0x33, (byte) 0x8d,
251             (byte) 0x99, (byte) 0x00, (byte) 0xdc, (byte) 0xf5, (byte) 0xb4, (byte) 0xa2,
252             (byte) 0x2f, (byte) 0xba, (byte) 0xe5, (byte) 0x62, (byte) 0x30, (byte) 0x6d,
253             (byte) 0xe6, (byte) 0x3d, (byte) 0xeb, (byte) 0x24, (byte) 0xc2, (byte) 0xdc,
254             (byte) 0x5f, (byte) 0xb7, (byte) 0x16, (byte) 0x35, (byte) 0xa3, (byte) 0x98,
255             (byte) 0x98, (byte) 0xa8, (byte) 0xef, (byte) 0xe8, (byte) 0xc4, (byte) 0x96,
256             (byte) 0x6d, (byte) 0x38, (byte) 0xab, (byte) 0x26, (byte) 0x6d, (byte) 0x30,
257             (byte) 0xc2, (byte) 0xa0, (byte) 0x44, (byte) 0xe4, (byte) 0xff, (byte) 0x7e,
258             (byte) 0xbe, (byte) 0x7c, (byte) 0x33, (byte) 0xa5, (byte) 0x10, (byte) 0xad,
259             (byte) 0xd7, (byte) 0x1e, (byte) 0x13, (byte) 0x20, (byte) 0xb3, (byte) 0x1f,
260             (byte) 0x41, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xf1, (byte) 0x89,
261             (byte) 0x07, (byte) 0x0f, (byte) 0xe8, (byte) 0xcf, (byte) 0xab, (byte) 0x13,
262             (byte) 0x2a, (byte) 0x8f, (byte) 0x88, (byte) 0x80, (byte) 0x11, (byte) 0x9a,
263             (byte) 0x79, (byte) 0xb6, (byte) 0x59, (byte) 0x3a, (byte) 0x50, (byte) 0x6e,
264             (byte) 0x57, (byte) 0x37, (byte) 0xab, (byte) 0x2a, (byte) 0xd2, (byte) 0xaa,
265             (byte) 0xd9, (byte) 0x72, (byte) 0x73, (byte) 0xff, (byte) 0x8b, (byte) 0x47,
266             (byte) 0x76, (byte) 0xdd, (byte) 0xdc, (byte) 0xf5, (byte) 0x97, (byte) 0x44,
267             (byte) 0x3a, (byte) 0x78, (byte) 0xbe, (byte) 0x17, (byte) 0xb4, (byte) 0x22,
268             (byte) 0x6f, (byte) 0xe5, (byte) 0x23, (byte) 0x70, (byte) 0x1d, (byte) 0x10,
269             (byte) 0x5d, (byte) 0xba, (byte) 0x16, (byte) 0x81, (byte) 0xf1, (byte) 0x45,
270             (byte) 0xce, (byte) 0x30, (byte) 0xb4, (byte) 0xab, (byte) 0x80, (byte) 0xe4,
271             (byte) 0x98, (byte) 0x31, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xda,
272             (byte) 0x82, (byte) 0x9d, (byte) 0x3f, (byte) 0xca, (byte) 0x2f, (byte) 0xe1,
273             (byte) 0xd4, (byte) 0x86, (byte) 0x77, (byte) 0x48, (byte) 0xa6, (byte) 0xab,
274             (byte) 0xab, (byte) 0x1c, (byte) 0x42, (byte) 0x5c, (byte) 0xd5, (byte) 0xc7,
275             (byte) 0x46, (byte) 0x59, (byte) 0x91, (byte) 0x3f, (byte) 0xfc, (byte) 0xcc,
276             (byte) 0xec, (byte) 0xc2, (byte) 0x40, (byte) 0x12, (byte) 0x2c, (byte) 0x8d,
277             (byte) 0x1f, (byte) 0xa2, (byte) 0x18, (byte) 0x88, (byte) 0xee, (byte) 0x82,
278             (byte) 0x4a, (byte) 0x5a, (byte) 0x5e, (byte) 0x88, (byte) 0x20, (byte) 0xe3,
279             (byte) 0x7b, (byte) 0xe0, (byte) 0xd8, (byte) 0x3a, (byte) 0x52, (byte) 0x9a,
280             (byte) 0x26, (byte) 0x6a, (byte) 0x04, (byte) 0xec, (byte) 0xe8, (byte) 0xb9,
281             (byte) 0x48, (byte) 0x40, (byte) 0xe1, (byte) 0xe1, (byte) 0x83, (byte) 0xa6,
282             (byte) 0x67, (byte) 0xa6, (byte) 0xfd, (byte) 0x02, (byte) 0x41, (byte) 0x00,
283             (byte) 0x89, (byte) 0x72, (byte) 0x3e, (byte) 0xb0, (byte) 0x90, (byte) 0xfd,
284             (byte) 0x4c, (byte) 0x0e, (byte) 0xd6, (byte) 0x13, (byte) 0x63, (byte) 0xcb,
285             (byte) 0xed, (byte) 0x38, (byte) 0x88, (byte) 0xb6, (byte) 0x79, (byte) 0xc4,
286             (byte) 0x33, (byte) 0x6c, (byte) 0xf6, (byte) 0xf8, (byte) 0xd8, (byte) 0xd0,
287             (byte) 0xbf, (byte) 0x9d, (byte) 0x35, (byte) 0xac, (byte) 0x69, (byte) 0xd2,
288             (byte) 0x2b, (byte) 0xc1, (byte) 0xf9, (byte) 0x24, (byte) 0x7b, (byte) 0xce,
289             (byte) 0xcd, (byte) 0xcb, (byte) 0xa7, (byte) 0xb2, (byte) 0x7a, (byte) 0x0a,
290             (byte) 0x27, (byte) 0x19, (byte) 0xc9, (byte) 0xaf, (byte) 0x0d, (byte) 0x21,
291             (byte) 0x89, (byte) 0x88, (byte) 0x7c, (byte) 0xad, (byte) 0x9e, (byte) 0x8d,
292             (byte) 0x47, (byte) 0x6d, (byte) 0x3f, (byte) 0xce, (byte) 0x7b, (byte) 0xa1,
293             (byte) 0x74, (byte) 0xf1, (byte) 0xa0, (byte) 0xa1, (byte) 0x02, (byte) 0x41,
294             (byte) 0x00, (byte) 0xd9, (byte) 0xa8, (byte) 0xf5, (byte) 0xfe, (byte) 0xce,
295             (byte) 0xe6, (byte) 0x77, (byte) 0x6b, (byte) 0xfe, (byte) 0x2d, (byte) 0xe0,
296             (byte) 0x1e, (byte) 0xb6, (byte) 0x2e, (byte) 0x12, (byte) 0x4e, (byte) 0x40,
297             (byte) 0xaf, (byte) 0x6a, (byte) 0x7b, (byte) 0x37, (byte) 0x49, (byte) 0x2a,
298             (byte) 0x96, (byte) 0x25, (byte) 0x83, (byte) 0x49, (byte) 0xd4, (byte) 0x0c,
299             (byte) 0xc6, (byte) 0x78, (byte) 0x25, (byte) 0x24, (byte) 0x90, (byte) 0x90,
300             (byte) 0x06, (byte) 0x15, (byte) 0x9e, (byte) 0xfe, (byte) 0xf9, (byte) 0xdf,
301             (byte) 0x5b, (byte) 0xf3, (byte) 0x7e, (byte) 0x38, (byte) 0x70, (byte) 0xeb,
302             (byte) 0x57, (byte) 0xd0, (byte) 0xd9, (byte) 0xa7, (byte) 0x0e, (byte) 0x14,
303             (byte) 0xf7, (byte) 0x95, (byte) 0x68, (byte) 0xd5, (byte) 0xc8, (byte) 0xab,
304             (byte) 0x9d, (byte) 0x3a, (byte) 0x2b, (byte) 0x51, (byte) 0xf9, (byte) 0x02,
305             (byte) 0x41, (byte) 0x00, (byte) 0x96, (byte) 0xdf, (byte) 0xe9, (byte) 0x67,
306             (byte) 0x6c, (byte) 0xdc, (byte) 0x90, (byte) 0x14, (byte) 0xb4, (byte) 0x1d,
307             (byte) 0x22, (byte) 0x33, (byte) 0x4a, (byte) 0x31, (byte) 0xc1, (byte) 0x9d,
308             (byte) 0x2e, (byte) 0xff, (byte) 0x9a, (byte) 0x2a, (byte) 0x95, (byte) 0x4b,
309             (byte) 0x27, (byte) 0x74, (byte) 0xcb, (byte) 0x21, (byte) 0xc3, (byte) 0xd2,
310             (byte) 0x0b, (byte) 0xb2, (byte) 0x46, (byte) 0x87, (byte) 0xf8, (byte) 0x28,
311             (byte) 0x01, (byte) 0x8b, (byte) 0xd8, (byte) 0xb9, (byte) 0x4b, (byte) 0xcd,
312             (byte) 0x9a, (byte) 0x96, (byte) 0x41, (byte) 0x0e, (byte) 0x36, (byte) 0x6d,
313             (byte) 0x40, (byte) 0x42, (byte) 0xbc, (byte) 0xd9, (byte) 0xd3, (byte) 0x7b,
314             (byte) 0xbc, (byte) 0xa7, (byte) 0x92, (byte) 0x90, (byte) 0xdd, (byte) 0xa1,
315             (byte) 0x9c, (byte) 0xce, (byte) 0xa1, (byte) 0x87, (byte) 0x11, (byte) 0x51
316     };
317 
318     /**
319      * Generated from above and converted with:
320      *
321      * openssl x509 -outform d -in usercert.pem | xxd -i | sed 's/0x/(byte) 0x/g'
322      */
323     private static final byte[] FAKE_RSA_USER_1 = new byte[] {
324             (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x95, (byte) 0x30, (byte) 0x82,
325             (byte) 0x01, (byte) 0xfe, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01,
326             (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x0d,
327             (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
328             (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05,
329             (byte) 0x00, (byte) 0x30, (byte) 0x4f, (byte) 0x31, (byte) 0x0b, (byte) 0x30,
330             (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06,
331             (byte) 0x13, (byte) 0x02, (byte) 0x55, (byte) 0x53, (byte) 0x31, (byte) 0x0b,
332             (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
333             (byte) 0x08, (byte) 0x13, (byte) 0x02, (byte) 0x43, (byte) 0x41, (byte) 0x31,
334             (byte) 0x16, (byte) 0x30, (byte) 0x14, (byte) 0x06, (byte) 0x03, (byte) 0x55,
335             (byte) 0x04, (byte) 0x07, (byte) 0x13, (byte) 0x0d, (byte) 0x4d, (byte) 0x6f,
336             (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x61, (byte) 0x69, (byte) 0x6e,
337             (byte) 0x20, (byte) 0x56, (byte) 0x69, (byte) 0x65, (byte) 0x77, (byte) 0x31,
338             (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0x06, (byte) 0x03, (byte) 0x55,
339             (byte) 0x04, (byte) 0x0a, (byte) 0x13, (byte) 0x12, (byte) 0x41, (byte) 0x6e,
340             (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x20,
341             (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x43,
342             (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x30, (byte) 0x1e,
343             (byte) 0x17, (byte) 0x0d, (byte) 0x31, (byte) 0x32, (byte) 0x30, (byte) 0x38,
344             (byte) 0x31, (byte) 0x34, (byte) 0x32, (byte) 0x33, (byte) 0x32, (byte) 0x35,
345             (byte) 0x34, (byte) 0x38, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, (byte) 0x32,
346             (byte) 0x32, (byte) 0x30, (byte) 0x38, (byte) 0x31, (byte) 0x32, (byte) 0x32,
347             (byte) 0x33, (byte) 0x32, (byte) 0x35, (byte) 0x34, (byte) 0x38, (byte) 0x5a,
348             (byte) 0x30, (byte) 0x55, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09,
349             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13,
350             (byte) 0x02, (byte) 0x55, (byte) 0x53, (byte) 0x31, (byte) 0x0b, (byte) 0x30,
351             (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x08,
352             (byte) 0x13, (byte) 0x02, (byte) 0x43, (byte) 0x41, (byte) 0x31, (byte) 0x1b,
353             (byte) 0x30, (byte) 0x19, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
354             (byte) 0x0a, (byte) 0x13, (byte) 0x12, (byte) 0x41, (byte) 0x6e, (byte) 0x64,
355             (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x20, (byte) 0x54,
356             (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x43, (byte) 0x61,
357             (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x31, (byte) 0x1c, (byte) 0x30,
358             (byte) 0x1a, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03,
359             (byte) 0x13, (byte) 0x13, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76,
360             (byte) 0x65, (byte) 0x72, (byte) 0x31, (byte) 0x2e, (byte) 0x65, (byte) 0x78,
361             (byte) 0x61, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x65, (byte) 0x2e,
362             (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30, (byte) 0x81, (byte) 0x9f,
363             (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86,
364             (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01,
365             (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0x8d,
366             (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0x89, (byte) 0x02, (byte) 0x81,
367             (byte) 0x81, (byte) 0x00, (byte) 0xce, (byte) 0x29, (byte) 0xeb, (byte) 0xf6,
368             (byte) 0x5b, (byte) 0x25, (byte) 0xdc, (byte) 0xa1, (byte) 0xa6, (byte) 0x2c,
369             (byte) 0x66, (byte) 0xcb, (byte) 0x20, (byte) 0x90, (byte) 0x27, (byte) 0x86,
370             (byte) 0x8a, (byte) 0x44, (byte) 0x71, (byte) 0x50, (byte) 0xda, (byte) 0xd3,
371             (byte) 0x02, (byte) 0x77, (byte) 0x55, (byte) 0xe9, (byte) 0xe8, (byte) 0x08,
372             (byte) 0xf3, (byte) 0x36, (byte) 0x9a, (byte) 0xae, (byte) 0xab, (byte) 0x04,
373             (byte) 0x6d, (byte) 0x00, (byte) 0x99, (byte) 0xbf, (byte) 0x7d, (byte) 0x0f,
374             (byte) 0x67, (byte) 0x8b, (byte) 0x1d, (byte) 0xd4, (byte) 0x2b, (byte) 0x7c,
375             (byte) 0xcb, (byte) 0xcd, (byte) 0x33, (byte) 0xc7, (byte) 0x84, (byte) 0x30,
376             (byte) 0xe2, (byte) 0x45, (byte) 0x21, (byte) 0xb3, (byte) 0x75, (byte) 0xf5,
377             (byte) 0x79, (byte) 0x02, (byte) 0xda, (byte) 0x50, (byte) 0xa3, (byte) 0x8b,
378             (byte) 0xce, (byte) 0xc3, (byte) 0x8e, (byte) 0x0f, (byte) 0x25, (byte) 0xeb,
379             (byte) 0x08, (byte) 0x2c, (byte) 0xdd, (byte) 0x1c, (byte) 0xcf, (byte) 0xff,
380             (byte) 0x3b, (byte) 0xde, (byte) 0xb6, (byte) 0xaa, (byte) 0x2a, (byte) 0xa9,
381             (byte) 0xc4, (byte) 0x8a, (byte) 0x24, (byte) 0x24, (byte) 0xe6, (byte) 0x29,
382             (byte) 0x0d, (byte) 0x98, (byte) 0x4c, (byte) 0x32, (byte) 0xa1, (byte) 0x7b,
383             (byte) 0x23, (byte) 0x2b, (byte) 0x42, (byte) 0x30, (byte) 0xee, (byte) 0x78,
384             (byte) 0x08, (byte) 0x47, (byte) 0xad, (byte) 0xf2, (byte) 0x96, (byte) 0xd5,
385             (byte) 0xf1, (byte) 0x62, (byte) 0x42, (byte) 0x2d, (byte) 0x35, (byte) 0x19,
386             (byte) 0xb4, (byte) 0x3c, (byte) 0xc9, (byte) 0xc3, (byte) 0x5f, (byte) 0x03,
387             (byte) 0x16, (byte) 0x3a, (byte) 0x23, (byte) 0xac, (byte) 0xcb, (byte) 0xce,
388             (byte) 0x9e, (byte) 0x51, (byte) 0x2e, (byte) 0x6d, (byte) 0x02, (byte) 0x03,
389             (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xa3, (byte) 0x7b, (byte) 0x30,
390             (byte) 0x79, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55,
391             (byte) 0x1d, (byte) 0x13, (byte) 0x04, (byte) 0x02, (byte) 0x30, (byte) 0x00,
392             (byte) 0x30, (byte) 0x2c, (byte) 0x06, (byte) 0x09, (byte) 0x60, (byte) 0x86,
393             (byte) 0x48, (byte) 0x01, (byte) 0x86, (byte) 0xf8, (byte) 0x42, (byte) 0x01,
394             (byte) 0x0d, (byte) 0x04, (byte) 0x1f, (byte) 0x16, (byte) 0x1d, (byte) 0x4f,
395             (byte) 0x70, (byte) 0x65, (byte) 0x6e, (byte) 0x53, (byte) 0x53, (byte) 0x4c,
396             (byte) 0x20, (byte) 0x47, (byte) 0x65, (byte) 0x6e, (byte) 0x65, (byte) 0x72,
397             (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x43,
398             (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69,
399             (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x30, (byte) 0x1d,
400             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04,
401             (byte) 0x16, (byte) 0x04, (byte) 0x14, (byte) 0x32, (byte) 0xa1, (byte) 0x1e,
402             (byte) 0x6b, (byte) 0x69, (byte) 0x04, (byte) 0xfe, (byte) 0xb3, (byte) 0xcd,
403             (byte) 0xf8, (byte) 0xbb, (byte) 0x14, (byte) 0xcd, (byte) 0xff, (byte) 0xd4,
404             (byte) 0x16, (byte) 0xc3, (byte) 0xab, (byte) 0x44, (byte) 0x2f, (byte) 0x30,
405             (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23,
406             (byte) 0x04, (byte) 0x18, (byte) 0x30, (byte) 0x16, (byte) 0x80, (byte) 0x14,
407             (byte) 0x33, (byte) 0x05, (byte) 0xee, (byte) 0xfe, (byte) 0x6f, (byte) 0x60,
408             (byte) 0xc7, (byte) 0xf9, (byte) 0xa9, (byte) 0xd2, (byte) 0x73, (byte) 0x5c,
409             (byte) 0x8f, (byte) 0x6d, (byte) 0xa2, (byte) 0x2f, (byte) 0x97, (byte) 0x8e,
410             (byte) 0x5d, (byte) 0x51, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09,
411             (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d,
412             (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x03,
413             (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0x46, (byte) 0x42, (byte) 0xef,
414             (byte) 0x56, (byte) 0x89, (byte) 0x78, (byte) 0x90, (byte) 0x38, (byte) 0x24,
415             (byte) 0x9f, (byte) 0x8c, (byte) 0x7a, (byte) 0xce, (byte) 0x7a, (byte) 0xa5,
416             (byte) 0xb5, (byte) 0x1e, (byte) 0x74, (byte) 0x96, (byte) 0x34, (byte) 0x49,
417             (byte) 0x8b, (byte) 0xed, (byte) 0x44, (byte) 0xb3, (byte) 0xc9, (byte) 0x05,
418             (byte) 0xd7, (byte) 0x48, (byte) 0x55, (byte) 0x52, (byte) 0x59, (byte) 0x15,
419             (byte) 0x0b, (byte) 0xaa, (byte) 0x16, (byte) 0x86, (byte) 0xd2, (byte) 0x8e,
420             (byte) 0x16, (byte) 0x99, (byte) 0xe8, (byte) 0x5f, (byte) 0x11, (byte) 0x71,
421             (byte) 0x42, (byte) 0x55, (byte) 0xd1, (byte) 0xc4, (byte) 0x6f, (byte) 0x2e,
422             (byte) 0xa9, (byte) 0x64, (byte) 0x6f, (byte) 0xd8, (byte) 0xfd, (byte) 0x43,
423             (byte) 0x13, (byte) 0x24, (byte) 0xaa, (byte) 0x67, (byte) 0xe6, (byte) 0xf5,
424             (byte) 0xca, (byte) 0x80, (byte) 0x5e, (byte) 0x3a, (byte) 0x3e, (byte) 0xcc,
425             (byte) 0x4f, (byte) 0xba, (byte) 0x87, (byte) 0xe6, (byte) 0xae, (byte) 0xbf,
426             (byte) 0x8f, (byte) 0xd5, (byte) 0x28, (byte) 0x38, (byte) 0x58, (byte) 0x30,
427             (byte) 0x24, (byte) 0xf6, (byte) 0x53, (byte) 0x5b, (byte) 0x41, (byte) 0x53,
428             (byte) 0xe6, (byte) 0x45, (byte) 0xbc, (byte) 0xbe, (byte) 0xe6, (byte) 0xbb,
429             (byte) 0x5d, (byte) 0xd8, (byte) 0xa7, (byte) 0xf9, (byte) 0x64, (byte) 0x99,
430             (byte) 0x04, (byte) 0x43, (byte) 0x75, (byte) 0xd7, (byte) 0x2d, (byte) 0x32,
431             (byte) 0x0a, (byte) 0x94, (byte) 0xaf, (byte) 0x06, (byte) 0x34, (byte) 0xae,
432             (byte) 0x46, (byte) 0xbd, (byte) 0xda, (byte) 0x00, (byte) 0x0e, (byte) 0x25,
433             (byte) 0xc2, (byte) 0xf7, (byte) 0xc9, (byte) 0xc3, (byte) 0x65, (byte) 0xd2,
434             (byte) 0x08, (byte) 0x41, (byte) 0x0a, (byte) 0xf3, (byte) 0x72
435     };
436 
437     /*
438      * The keys and certificates below are generated with:
439      *
440      * openssl req -new -x509 -days 3650 -extensions v3_ca -keyout cakey.pem -out cacert.pem
441      * openssl ecparam -name prime256v1 -out ecparam.pem
442      * openssl req -newkey ec:ecparam.pem -keyout userkey.pem -nodes -days 3650 -out userkey.req
443      * mkdir -p demoCA/newcerts
444      * touch demoCA/index.txt
445      * echo "01" > demoCA/serial
446      * openssl ca -out usercert.pem -in userkey.req -cert cacert.pem -keyfile cakey.pem -days 3650
447      */
448 
449     /**
450      * Generated from above and converted with:
451      *
452      * openssl x509 -outform d -in cacert.pem | xxd -i | sed 's/0x/(byte) 0x/g'
453      */
454     private static final byte[] FAKE_EC_CA_1 = {
455             (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x58, (byte) 0x30, (byte) 0x82,
456             (byte) 0x01, (byte) 0xc1, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01,
457             (byte) 0x02, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0xe1, (byte) 0xb2,
458             (byte) 0x8c, (byte) 0x04, (byte) 0x95, (byte) 0xeb, (byte) 0x10, (byte) 0xcb,
459             (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86,
460             (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01,
461             (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x30, (byte) 0x45, (byte) 0x31,
462             (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55,
463             (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55,
464             (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03,
465             (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53,
466             (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74,
467             (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x21, (byte) 0x30,
468             (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a,
469             (byte) 0x0c, (byte) 0x18, (byte) 0x49, (byte) 0x6e, (byte) 0x74, (byte) 0x65,
470             (byte) 0x72, (byte) 0x6e, (byte) 0x65, (byte) 0x74, (byte) 0x20, (byte) 0x57,
471             (byte) 0x69, (byte) 0x64, (byte) 0x67, (byte) 0x69, (byte) 0x74, (byte) 0x73,
472             (byte) 0x20, (byte) 0x50, (byte) 0x74, (byte) 0x79, (byte) 0x20, (byte) 0x4c,
473             (byte) 0x74, (byte) 0x64, (byte) 0x30, (byte) 0x1e, (byte) 0x17, (byte) 0x0d,
474             (byte) 0x31, (byte) 0x33, (byte) 0x30, (byte) 0x38, (byte) 0x32, (byte) 0x37,
475             (byte) 0x31, (byte) 0x36, (byte) 0x32, (byte) 0x38, (byte) 0x32, (byte) 0x38,
476             (byte) 0x5a, (byte) 0x17, (byte) 0x0d, (byte) 0x32, (byte) 0x33, (byte) 0x30,
477             (byte) 0x38, (byte) 0x32, (byte) 0x35, (byte) 0x31, (byte) 0x36, (byte) 0x32,
478             (byte) 0x38, (byte) 0x32, (byte) 0x38, (byte) 0x5a, (byte) 0x30, (byte) 0x45,
479             (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03,
480             (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41,
481             (byte) 0x55, (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06,
482             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a,
483             (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53,
484             (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x21,
485             (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
486             (byte) 0x0a, (byte) 0x0c, (byte) 0x18, (byte) 0x49, (byte) 0x6e, (byte) 0x74,
487             (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x65, (byte) 0x74, (byte) 0x20,
488             (byte) 0x57, (byte) 0x69, (byte) 0x64, (byte) 0x67, (byte) 0x69, (byte) 0x74,
489             (byte) 0x73, (byte) 0x20, (byte) 0x50, (byte) 0x74, (byte) 0x79, (byte) 0x20,
490             (byte) 0x4c, (byte) 0x74, (byte) 0x64, (byte) 0x30, (byte) 0x81, (byte) 0x9f,
491             (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86,
492             (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01,
493             (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0x8d,
494             (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0x89, (byte) 0x02, (byte) 0x81,
495             (byte) 0x81, (byte) 0x00, (byte) 0xb5, (byte) 0xf6, (byte) 0x08, (byte) 0x0f,
496             (byte) 0xc4, (byte) 0x4d, (byte) 0xe4, (byte) 0x0d, (byte) 0x34, (byte) 0x1d,
497             (byte) 0xe2, (byte) 0x23, (byte) 0x18, (byte) 0x63, (byte) 0x03, (byte) 0xf7,
498             (byte) 0x14, (byte) 0x0e, (byte) 0x98, (byte) 0xcd, (byte) 0x45, (byte) 0x1f,
499             (byte) 0xfe, (byte) 0xfb, (byte) 0x09, (byte) 0x3f, (byte) 0x5d, (byte) 0x36,
500             (byte) 0x3b, (byte) 0x0f, (byte) 0xf9, (byte) 0x5e, (byte) 0x86, (byte) 0x56,
501             (byte) 0x64, (byte) 0xd7, (byte) 0x3f, (byte) 0xae, (byte) 0x33, (byte) 0x09,
502             (byte) 0xd3, (byte) 0xdd, (byte) 0x06, (byte) 0x17, (byte) 0x26, (byte) 0xdc,
503             (byte) 0xa2, (byte) 0x8c, (byte) 0x3c, (byte) 0x65, (byte) 0xed, (byte) 0x03,
504             (byte) 0x82, (byte) 0x78, (byte) 0x9b, (byte) 0xee, (byte) 0xe3, (byte) 0x98,
505             (byte) 0x58, (byte) 0xe1, (byte) 0xf1, (byte) 0xa0, (byte) 0x85, (byte) 0xae,
506             (byte) 0x63, (byte) 0x84, (byte) 0x41, (byte) 0x46, (byte) 0xa7, (byte) 0x4f,
507             (byte) 0xdc, (byte) 0xbb, (byte) 0x1c, (byte) 0x6e, (byte) 0xec, (byte) 0x7b,
508             (byte) 0xd5, (byte) 0xab, (byte) 0x3d, (byte) 0x6a, (byte) 0x05, (byte) 0x58,
509             (byte) 0x0f, (byte) 0x9b, (byte) 0x6a, (byte) 0x67, (byte) 0x4b, (byte) 0xe9,
510             (byte) 0x2a, (byte) 0x6d, (byte) 0x96, (byte) 0x11, (byte) 0x53, (byte) 0x95,
511             (byte) 0x78, (byte) 0xaa, (byte) 0xd1, (byte) 0x91, (byte) 0x4a, (byte) 0xf8,
512             (byte) 0x54, (byte) 0x52, (byte) 0x6d, (byte) 0xb9, (byte) 0xca, (byte) 0x74,
513             (byte) 0x81, (byte) 0xf8, (byte) 0x99, (byte) 0x64, (byte) 0xd1, (byte) 0x4f,
514             (byte) 0x01, (byte) 0x38, (byte) 0x4f, (byte) 0x08, (byte) 0x5c, (byte) 0x31,
515             (byte) 0xcb, (byte) 0x7c, (byte) 0x5c, (byte) 0x78, (byte) 0x5d, (byte) 0x47,
516             (byte) 0xd9, (byte) 0xf0, (byte) 0x1a, (byte) 0xeb, (byte) 0x02, (byte) 0x03,
517             (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xa3, (byte) 0x50, (byte) 0x30,
518             (byte) 0x4e, (byte) 0x30, (byte) 0x1d, (byte) 0x06, (byte) 0x03, (byte) 0x55,
519             (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16, (byte) 0x04, (byte) 0x14,
520             (byte) 0x5f, (byte) 0x5b, (byte) 0x5e, (byte) 0xac, (byte) 0x29, (byte) 0xfa,
521             (byte) 0xa1, (byte) 0x9f, (byte) 0x9e, (byte) 0xad, (byte) 0x46, (byte) 0xe1,
522             (byte) 0xbc, (byte) 0x20, (byte) 0x72, (byte) 0xcf, (byte) 0x4a, (byte) 0xd4,
523             (byte) 0xfa, (byte) 0xe3, (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03,
524             (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, (byte) 0x18, (byte) 0x30,
525             (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0x5f, (byte) 0x5b, (byte) 0x5e,
526             (byte) 0xac, (byte) 0x29, (byte) 0xfa, (byte) 0xa1, (byte) 0x9f, (byte) 0x9e,
527             (byte) 0xad, (byte) 0x46, (byte) 0xe1, (byte) 0xbc, (byte) 0x20, (byte) 0x72,
528             (byte) 0xcf, (byte) 0x4a, (byte) 0xd4, (byte) 0xfa, (byte) 0xe3, (byte) 0x30,
529             (byte) 0x0c, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13,
530             (byte) 0x04, (byte) 0x05, (byte) 0x30, (byte) 0x03, (byte) 0x01, (byte) 0x01,
531             (byte) 0xff, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a,
532             (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01,
533             (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x81,
534             (byte) 0x81, (byte) 0x00, (byte) 0xa1, (byte) 0x4a, (byte) 0xe6, (byte) 0xfc,
535             (byte) 0x7f, (byte) 0x17, (byte) 0xaa, (byte) 0x65, (byte) 0x4a, (byte) 0x34,
536             (byte) 0xde, (byte) 0x69, (byte) 0x67, (byte) 0x54, (byte) 0x4d, (byte) 0xa2,
537             (byte) 0xc2, (byte) 0x98, (byte) 0x02, (byte) 0x43, (byte) 0x6a, (byte) 0x0e,
538             (byte) 0x0b, (byte) 0x7f, (byte) 0xa4, (byte) 0x46, (byte) 0xaf, (byte) 0xa4,
539             (byte) 0x65, (byte) 0xa0, (byte) 0xdb, (byte) 0xf1, (byte) 0x5b, (byte) 0xd5,
540             (byte) 0x09, (byte) 0xbc, (byte) 0xee, (byte) 0x37, (byte) 0x51, (byte) 0x19,
541             (byte) 0x36, (byte) 0xc0, (byte) 0x90, (byte) 0xd3, (byte) 0x5f, (byte) 0xf3,
542             (byte) 0x4f, (byte) 0xb9, (byte) 0x08, (byte) 0x45, (byte) 0x0e, (byte) 0x01,
543             (byte) 0x8a, (byte) 0x95, (byte) 0xef, (byte) 0x92, (byte) 0x95, (byte) 0x33,
544             (byte) 0x78, (byte) 0xdd, (byte) 0x90, (byte) 0xbb, (byte) 0xf3, (byte) 0x06,
545             (byte) 0x75, (byte) 0xd0, (byte) 0x66, (byte) 0xe6, (byte) 0xd0, (byte) 0x18,
546             (byte) 0x6e, (byte) 0xeb, (byte) 0x1c, (byte) 0x52, (byte) 0xc3, (byte) 0x2e,
547             (byte) 0x57, (byte) 0x7d, (byte) 0xa9, (byte) 0x03, (byte) 0xdb, (byte) 0xf4,
548             (byte) 0x57, (byte) 0x5f, (byte) 0x6c, (byte) 0x7e, (byte) 0x00, (byte) 0x0d,
549             (byte) 0x8f, (byte) 0xe8, (byte) 0x91, (byte) 0xf7, (byte) 0xae, (byte) 0x24,
550             (byte) 0x35, (byte) 0x07, (byte) 0xb5, (byte) 0x48, (byte) 0x2d, (byte) 0x36,
551             (byte) 0x30, (byte) 0x5d, (byte) 0xe9, (byte) 0x49, (byte) 0x2d, (byte) 0xd1,
552             (byte) 0x5d, (byte) 0xc5, (byte) 0xf4, (byte) 0x33, (byte) 0x77, (byte) 0x3c,
553             (byte) 0x71, (byte) 0xad, (byte) 0x90, (byte) 0x65, (byte) 0xa9, (byte) 0xc1,
554             (byte) 0x0b, (byte) 0x5c, (byte) 0x62, (byte) 0x55, (byte) 0x50, (byte) 0x6f,
555             (byte) 0x9b, (byte) 0xc9, (byte) 0x0d, (byte) 0xee
556     };
557 
558     /**
559      * Generated from above and converted with:
560      *
561      * openssl pkcs8 -topk8 -outform d -in userkey.pem -nocrypt | xxd -i | sed 's/0x/(byte) 0x/g'
562      */
563     private static final byte[] FAKE_EC_KEY_1 = new byte[] {
564             (byte) 0x30, (byte) 0x81, (byte) 0x87, (byte) 0x02, (byte) 0x01, (byte) 0x00,
565             (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x07, (byte) 0x2a, (byte) 0x86,
566             (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x02, (byte) 0x01, (byte) 0x06,
567             (byte) 0x08, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d,
568             (byte) 0x03, (byte) 0x01, (byte) 0x07, (byte) 0x04, (byte) 0x6d, (byte) 0x30,
569             (byte) 0x6b, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x04, (byte) 0x20,
570             (byte) 0x3a, (byte) 0x8a, (byte) 0x02, (byte) 0xdc, (byte) 0xde, (byte) 0x70,
571             (byte) 0x84, (byte) 0x45, (byte) 0x34, (byte) 0xaf, (byte) 0xbd, (byte) 0xd5,
572             (byte) 0x02, (byte) 0x17, (byte) 0x69, (byte) 0x90, (byte) 0x65, (byte) 0x1e,
573             (byte) 0x87, (byte) 0xf1, (byte) 0x3d, (byte) 0x17, (byte) 0xb6, (byte) 0xf4,
574             (byte) 0x31, (byte) 0x94, (byte) 0x86, (byte) 0x76, (byte) 0x55, (byte) 0xf7,
575             (byte) 0xcc, (byte) 0xba, (byte) 0xa1, (byte) 0x44, (byte) 0x03, (byte) 0x42,
576             (byte) 0x00, (byte) 0x04, (byte) 0xd9, (byte) 0xcf, (byte) 0xe7, (byte) 0x9b,
577             (byte) 0x23, (byte) 0xc8, (byte) 0xa3, (byte) 0xb8, (byte) 0x33, (byte) 0x14,
578             (byte) 0xa4, (byte) 0x4d, (byte) 0x75, (byte) 0x90, (byte) 0xf3, (byte) 0xcd,
579             (byte) 0x43, (byte) 0xe5, (byte) 0x1b, (byte) 0x05, (byte) 0x1d, (byte) 0xf3,
580             (byte) 0xd0, (byte) 0xa3, (byte) 0xb7, (byte) 0x32, (byte) 0x5f, (byte) 0x79,
581             (byte) 0xdc, (byte) 0x88, (byte) 0xb8, (byte) 0x4d, (byte) 0xb3, (byte) 0xd1,
582             (byte) 0x6d, (byte) 0xf7, (byte) 0x75, (byte) 0xf3, (byte) 0xbf, (byte) 0x50,
583             (byte) 0xa1, (byte) 0xbc, (byte) 0x03, (byte) 0x64, (byte) 0x22, (byte) 0xe6,
584             (byte) 0x1a, (byte) 0xa1, (byte) 0xe1, (byte) 0x06, (byte) 0x68, (byte) 0x3b,
585             (byte) 0xbc, (byte) 0x9f, (byte) 0xd3, (byte) 0xae, (byte) 0x77, (byte) 0x5e,
586             (byte) 0x88, (byte) 0x0c, (byte) 0x5e, (byte) 0x0c, (byte) 0xb2, (byte) 0x38
587     };
588 
589     /**
590      * Generated from above and converted with:
591      *
592      * openssl x509 -outform d -in usercert.pem | xxd -i | sed 's/0x/(byte) 0x/g'
593      */
594     private static final byte[] FAKE_EC_USER_1 = new byte[] {
595             (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x51, (byte) 0x30, (byte) 0x82,
596             (byte) 0x01, (byte) 0xba, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01,
597             (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x0d,
598             (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
599             (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05,
600             (byte) 0x00, (byte) 0x30, (byte) 0x45, (byte) 0x31, (byte) 0x0b, (byte) 0x30,
601             (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06,
602             (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55, (byte) 0x31, (byte) 0x13,
603             (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
604             (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x6d,
605             (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x74,
606             (byte) 0x65, (byte) 0x31, (byte) 0x21, (byte) 0x30, (byte) 0x1f, (byte) 0x06,
607             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x18,
608             (byte) 0x49, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e,
609             (byte) 0x65, (byte) 0x74, (byte) 0x20, (byte) 0x57, (byte) 0x69, (byte) 0x64,
610             (byte) 0x67, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x20, (byte) 0x50,
611             (byte) 0x74, (byte) 0x79, (byte) 0x20, (byte) 0x4c, (byte) 0x74, (byte) 0x64,
612             (byte) 0x30, (byte) 0x1e, (byte) 0x17, (byte) 0x0d, (byte) 0x31, (byte) 0x33,
613             (byte) 0x30, (byte) 0x38, (byte) 0x32, (byte) 0x37, (byte) 0x31, (byte) 0x36,
614             (byte) 0x33, (byte) 0x30, (byte) 0x30, (byte) 0x38, (byte) 0x5a, (byte) 0x17,
615             (byte) 0x0d, (byte) 0x32, (byte) 0x33, (byte) 0x30, (byte) 0x38, (byte) 0x32,
616             (byte) 0x35, (byte) 0x31, (byte) 0x36, (byte) 0x33, (byte) 0x30, (byte) 0x30,
617             (byte) 0x38, (byte) 0x5a, (byte) 0x30, (byte) 0x62, (byte) 0x31, (byte) 0x0b,
618             (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
619             (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55, (byte) 0x31,
620             (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55,
621             (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53, (byte) 0x6f,
622             (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74, (byte) 0x61,
623             (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x21, (byte) 0x30, (byte) 0x1f,
624             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c,
625             (byte) 0x18, (byte) 0x49, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72,
626             (byte) 0x6e, (byte) 0x65, (byte) 0x74, (byte) 0x20, (byte) 0x57, (byte) 0x69,
627             (byte) 0x64, (byte) 0x67, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x20,
628             (byte) 0x50, (byte) 0x74, (byte) 0x79, (byte) 0x20, (byte) 0x4c, (byte) 0x74,
629             (byte) 0x64, (byte) 0x31, (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0x06,
630             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x12,
631             (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x65, (byte) 0x72,
632             (byte) 0x2e, (byte) 0x65, (byte) 0x78, (byte) 0x61, (byte) 0x6d, (byte) 0x70,
633             (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d,
634             (byte) 0x30, (byte) 0x59, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x07,
635             (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x02,
636             (byte) 0x01, (byte) 0x06, (byte) 0x08, (byte) 0x2a, (byte) 0x86, (byte) 0x48,
637             (byte) 0xce, (byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x07, (byte) 0x03,
638             (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0xd9, (byte) 0xcf, (byte) 0xe7,
639             (byte) 0x9b, (byte) 0x23, (byte) 0xc8, (byte) 0xa3, (byte) 0xb8, (byte) 0x33,
640             (byte) 0x14, (byte) 0xa4, (byte) 0x4d, (byte) 0x75, (byte) 0x90, (byte) 0xf3,
641             (byte) 0xcd, (byte) 0x43, (byte) 0xe5, (byte) 0x1b, (byte) 0x05, (byte) 0x1d,
642             (byte) 0xf3, (byte) 0xd0, (byte) 0xa3, (byte) 0xb7, (byte) 0x32, (byte) 0x5f,
643             (byte) 0x79, (byte) 0xdc, (byte) 0x88, (byte) 0xb8, (byte) 0x4d, (byte) 0xb3,
644             (byte) 0xd1, (byte) 0x6d, (byte) 0xf7, (byte) 0x75, (byte) 0xf3, (byte) 0xbf,
645             (byte) 0x50, (byte) 0xa1, (byte) 0xbc, (byte) 0x03, (byte) 0x64, (byte) 0x22,
646             (byte) 0xe6, (byte) 0x1a, (byte) 0xa1, (byte) 0xe1, (byte) 0x06, (byte) 0x68,
647             (byte) 0x3b, (byte) 0xbc, (byte) 0x9f, (byte) 0xd3, (byte) 0xae, (byte) 0x77,
648             (byte) 0x5e, (byte) 0x88, (byte) 0x0c, (byte) 0x5e, (byte) 0x0c, (byte) 0xb2,
649             (byte) 0x38, (byte) 0xa3, (byte) 0x7b, (byte) 0x30, (byte) 0x79, (byte) 0x30,
650             (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13,
651             (byte) 0x04, (byte) 0x02, (byte) 0x30, (byte) 0x00, (byte) 0x30, (byte) 0x2c,
652             (byte) 0x06, (byte) 0x09, (byte) 0x60, (byte) 0x86, (byte) 0x48, (byte) 0x01,
653             (byte) 0x86, (byte) 0xf8, (byte) 0x42, (byte) 0x01, (byte) 0x0d, (byte) 0x04,
654             (byte) 0x1f, (byte) 0x16, (byte) 0x1d, (byte) 0x4f, (byte) 0x70, (byte) 0x65,
655             (byte) 0x6e, (byte) 0x53, (byte) 0x53, (byte) 0x4c, (byte) 0x20, (byte) 0x47,
656             (byte) 0x65, (byte) 0x6e, (byte) 0x65, (byte) 0x72, (byte) 0x61, (byte) 0x74,
657             (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x43, (byte) 0x65, (byte) 0x72,
658             (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61,
659             (byte) 0x74, (byte) 0x65, (byte) 0x30, (byte) 0x1d, (byte) 0x06, (byte) 0x03,
660             (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16, (byte) 0x04,
661             (byte) 0x14, (byte) 0xd5, (byte) 0xc4, (byte) 0x72, (byte) 0xbd, (byte) 0xd2,
662             (byte) 0x4e, (byte) 0x90, (byte) 0x1b, (byte) 0x14, (byte) 0x32, (byte) 0xdb,
663             (byte) 0x03, (byte) 0xae, (byte) 0xfa, (byte) 0x27, (byte) 0x7d, (byte) 0x8d,
664             (byte) 0xe4, (byte) 0x80, (byte) 0x58, (byte) 0x30, (byte) 0x1f, (byte) 0x06,
665             (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, (byte) 0x18,
666             (byte) 0x30, (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0x5f, (byte) 0x5b,
667             (byte) 0x5e, (byte) 0xac, (byte) 0x29, (byte) 0xfa, (byte) 0xa1, (byte) 0x9f,
668             (byte) 0x9e, (byte) 0xad, (byte) 0x46, (byte) 0xe1, (byte) 0xbc, (byte) 0x20,
669             (byte) 0x72, (byte) 0xcf, (byte) 0x4a, (byte) 0xd4, (byte) 0xfa, (byte) 0xe3,
670             (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86,
671             (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01,
672             (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0x81,
673             (byte) 0x00, (byte) 0x43, (byte) 0x99, (byte) 0x9f, (byte) 0x67, (byte) 0x08,
674             (byte) 0x43, (byte) 0xd5, (byte) 0x6b, (byte) 0x6f, (byte) 0xd7, (byte) 0x05,
675             (byte) 0xd6, (byte) 0x75, (byte) 0x34, (byte) 0x30, (byte) 0xca, (byte) 0x20,
676             (byte) 0x47, (byte) 0x61, (byte) 0xa1, (byte) 0x89, (byte) 0xb6, (byte) 0xf1,
677             (byte) 0x49, (byte) 0x7b, (byte) 0xd9, (byte) 0xb9, (byte) 0xe8, (byte) 0x1e,
678             (byte) 0x29, (byte) 0x74, (byte) 0x0a, (byte) 0x67, (byte) 0xc0, (byte) 0x7d,
679             (byte) 0xb8, (byte) 0xe6, (byte) 0x39, (byte) 0xa8, (byte) 0x5e, (byte) 0xc3,
680             (byte) 0xb0, (byte) 0xa1, (byte) 0x30, (byte) 0x6a, (byte) 0x1f, (byte) 0x1d,
681             (byte) 0xfc, (byte) 0x11, (byte) 0x59, (byte) 0x0b, (byte) 0xb9, (byte) 0xad,
682             (byte) 0x3a, (byte) 0x4e, (byte) 0x50, (byte) 0x0a, (byte) 0x61, (byte) 0xdb,
683             (byte) 0x75, (byte) 0x6b, (byte) 0xe5, (byte) 0x3f, (byte) 0x8d, (byte) 0xde,
684             (byte) 0x28, (byte) 0x68, (byte) 0xb1, (byte) 0x29, (byte) 0x9a, (byte) 0x18,
685             (byte) 0x8a, (byte) 0xfc, (byte) 0x3f, (byte) 0x13, (byte) 0x93, (byte) 0x29,
686             (byte) 0xed, (byte) 0x22, (byte) 0x7c, (byte) 0xb4, (byte) 0x50, (byte) 0xd5,
687             (byte) 0x4d, (byte) 0x32, (byte) 0x4d, (byte) 0x42, (byte) 0x2b, (byte) 0x29,
688             (byte) 0x97, (byte) 0x86, (byte) 0xc0, (byte) 0x01, (byte) 0x00, (byte) 0x25,
689             (byte) 0xf6, (byte) 0xd3, (byte) 0x2a, (byte) 0xd8, (byte) 0xda, (byte) 0x13,
690             (byte) 0x94, (byte) 0x12, (byte) 0x78, (byte) 0x14, (byte) 0x0b, (byte) 0x51,
691             (byte) 0xc0, (byte) 0x45, (byte) 0xb4, (byte) 0x02, (byte) 0x37, (byte) 0x98,
692             (byte) 0x42, (byte) 0x3c, (byte) 0xcb, (byte) 0x2e, (byte) 0xe4, (byte) 0x38,
693             (byte) 0x69, (byte) 0x1b, (byte) 0x72, (byte) 0xf0, (byte) 0xaa, (byte) 0x89,
694             (byte) 0x7e, (byte) 0xde, (byte) 0xb2
695     };
696 
697     /*
698      * The keys and certificates below are generated with:
699      *
700      * openssl req -new -x509 -days 3650 -extensions v3_ca -keyout cakey.pem -out cacert.pem
701      * openssl dsaparam -out dsaparam.pem 1024
702      * openssl req -newkey dsa:dsaparam.pem -keyout userkey.pem -nodes -days 3650 -out userkey.req
703      * mkdir -p demoCA/newcerts
704      * touch demoCA/index.txt
705      * echo "01" > demoCA/serial
706      * openssl ca -out usercert.pem -in userkey.req -cert cacert.pem -keyfile cakey.pem -days 3650
707      */
708 
709     /**
710      * Generated from above and converted with:
711      *
712      * openssl x509 -outform d -in cacert.pem | xxd -i | sed 's/0x/(byte) 0x/g'
713      */
714     private static final byte[] FAKE_DSA_CA_1 = new byte[] {
715             (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x8a, (byte) 0x30, (byte) 0x82,
716             (byte) 0x01, (byte) 0xf3, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01,
717             (byte) 0x02, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0x87, (byte) 0xc0,
718             (byte) 0x68, (byte) 0x7f, (byte) 0x42, (byte) 0x92, (byte) 0x0b, (byte) 0x7a,
719             (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86,
720             (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01,
721             (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x30, (byte) 0x5e, (byte) 0x31,
722             (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55,
723             (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55,
724             (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03,
725             (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53,
726             (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74,
727             (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x21, (byte) 0x30,
728             (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a,
729             (byte) 0x0c, (byte) 0x18, (byte) 0x49, (byte) 0x6e, (byte) 0x74, (byte) 0x65,
730             (byte) 0x72, (byte) 0x6e, (byte) 0x65, (byte) 0x74, (byte) 0x20, (byte) 0x57,
731             (byte) 0x69, (byte) 0x64, (byte) 0x67, (byte) 0x69, (byte) 0x74, (byte) 0x73,
732             (byte) 0x20, (byte) 0x50, (byte) 0x74, (byte) 0x79, (byte) 0x20, (byte) 0x4c,
733             (byte) 0x74, (byte) 0x64, (byte) 0x31, (byte) 0x17, (byte) 0x30, (byte) 0x15,
734             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c,
735             (byte) 0x0e, (byte) 0x63, (byte) 0x61, (byte) 0x2e, (byte) 0x65, (byte) 0x78,
736             (byte) 0x61, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x65, (byte) 0x2e,
737             (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30, (byte) 0x1e, (byte) 0x17,
738             (byte) 0x0d, (byte) 0x31, (byte) 0x33, (byte) 0x30, (byte) 0x38, (byte) 0x32,
739             (byte) 0x37, (byte) 0x32, (byte) 0x33, (byte) 0x33, (byte) 0x31, (byte) 0x32,
740             (byte) 0x39, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, (byte) 0x32, (byte) 0x33,
741             (byte) 0x30, (byte) 0x38, (byte) 0x32, (byte) 0x35, (byte) 0x32, (byte) 0x33,
742             (byte) 0x33, (byte) 0x31, (byte) 0x32, (byte) 0x39, (byte) 0x5a, (byte) 0x30,
743             (byte) 0x5e, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06,
744             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02,
745             (byte) 0x41, (byte) 0x55, (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11,
746             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c,
747             (byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d,
748             (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31,
749             (byte) 0x21, (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55,
750             (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x18, (byte) 0x49, (byte) 0x6e,
751             (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x65, (byte) 0x74,
752             (byte) 0x20, (byte) 0x57, (byte) 0x69, (byte) 0x64, (byte) 0x67, (byte) 0x69,
753             (byte) 0x74, (byte) 0x73, (byte) 0x20, (byte) 0x50, (byte) 0x74, (byte) 0x79,
754             (byte) 0x20, (byte) 0x4c, (byte) 0x74, (byte) 0x64, (byte) 0x31, (byte) 0x17,
755             (byte) 0x30, (byte) 0x15, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
756             (byte) 0x03, (byte) 0x0c, (byte) 0x0e, (byte) 0x63, (byte) 0x61, (byte) 0x2e,
757             (byte) 0x65, (byte) 0x78, (byte) 0x61, (byte) 0x6d, (byte) 0x70, (byte) 0x6c,
758             (byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30,
759             (byte) 0x81, (byte) 0x9f, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09,
760             (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d,
761             (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x03,
762             (byte) 0x81, (byte) 0x8d, (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0x89,
763             (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xa4, (byte) 0xc7,
764             (byte) 0x06, (byte) 0xba, (byte) 0xdf, (byte) 0x2b, (byte) 0xee, (byte) 0xd2,
765             (byte) 0xb9, (byte) 0xe4, (byte) 0x52, (byte) 0x21, (byte) 0x68, (byte) 0x2b,
766             (byte) 0x83, (byte) 0xdf, (byte) 0xe3, (byte) 0x9c, (byte) 0x08, (byte) 0x73,
767             (byte) 0xdd, (byte) 0x90, (byte) 0xea, (byte) 0x97, (byte) 0x0c, (byte) 0x96,
768             (byte) 0x20, (byte) 0xb1, (byte) 0xee, (byte) 0x11, (byte) 0xd5, (byte) 0xd4,
769             (byte) 0x7c, (byte) 0x44, (byte) 0x96, (byte) 0x2e, (byte) 0x6e, (byte) 0xa2,
770             (byte) 0xb2, (byte) 0xa3, (byte) 0x4b, (byte) 0x0f, (byte) 0x32, (byte) 0x90,
771             (byte) 0xaf, (byte) 0x5c, (byte) 0x6f, (byte) 0x00, (byte) 0x88, (byte) 0x45,
772             (byte) 0x4e, (byte) 0x9b, (byte) 0x26, (byte) 0xc1, (byte) 0x94, (byte) 0x3c,
773             (byte) 0xfe, (byte) 0x10, (byte) 0xbd, (byte) 0xda, (byte) 0xf2, (byte) 0x8d,
774             (byte) 0x03, (byte) 0x52, (byte) 0x32, (byte) 0x11, (byte) 0xff, (byte) 0xf6,
775             (byte) 0xf9, (byte) 0x6e, (byte) 0x8f, (byte) 0x0f, (byte) 0xc8, (byte) 0x0a,
776             (byte) 0x48, (byte) 0x39, (byte) 0x33, (byte) 0xb9, (byte) 0x0c, (byte) 0xb3,
777             (byte) 0x2b, (byte) 0xab, (byte) 0x7d, (byte) 0x79, (byte) 0x6f, (byte) 0x57,
778             (byte) 0x5b, (byte) 0xb8, (byte) 0x84, (byte) 0xb6, (byte) 0xcc, (byte) 0xe8,
779             (byte) 0x30, (byte) 0x78, (byte) 0xff, (byte) 0x92, (byte) 0xe5, (byte) 0x43,
780             (byte) 0x2e, (byte) 0xef, (byte) 0x66, (byte) 0x98, (byte) 0xb4, (byte) 0xfe,
781             (byte) 0xa2, (byte) 0x40, (byte) 0xf2, (byte) 0x1f, (byte) 0xd0, (byte) 0x86,
782             (byte) 0x16, (byte) 0xc8, (byte) 0x45, (byte) 0xc4, (byte) 0x52, (byte) 0xcb,
783             (byte) 0x31, (byte) 0x5c, (byte) 0x9f, (byte) 0x32, (byte) 0x3b, (byte) 0xf7,
784             (byte) 0x19, (byte) 0x08, (byte) 0xc7, (byte) 0x00, (byte) 0x21, (byte) 0x7d,
785             (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xa3,
786             (byte) 0x50, (byte) 0x30, (byte) 0x4e, (byte) 0x30, (byte) 0x1d, (byte) 0x06,
787             (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16,
788             (byte) 0x04, (byte) 0x14, (byte) 0x47, (byte) 0x82, (byte) 0xa3, (byte) 0xf1,
789             (byte) 0xc2, (byte) 0x7e, (byte) 0x3a, (byte) 0xde, (byte) 0x4f, (byte) 0x30,
790             (byte) 0x4c, (byte) 0x7f, (byte) 0x72, (byte) 0x81, (byte) 0x15, (byte) 0x32,
791             (byte) 0xda, (byte) 0x7f, (byte) 0x58, (byte) 0x18, (byte) 0x30, (byte) 0x1f,
792             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04,
793             (byte) 0x18, (byte) 0x30, (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0x47,
794             (byte) 0x82, (byte) 0xa3, (byte) 0xf1, (byte) 0xc2, (byte) 0x7e, (byte) 0x3a,
795             (byte) 0xde, (byte) 0x4f, (byte) 0x30, (byte) 0x4c, (byte) 0x7f, (byte) 0x72,
796             (byte) 0x81, (byte) 0x15, (byte) 0x32, (byte) 0xda, (byte) 0x7f, (byte) 0x58,
797             (byte) 0x18, (byte) 0x30, (byte) 0x0c, (byte) 0x06, (byte) 0x03, (byte) 0x55,
798             (byte) 0x1d, (byte) 0x13, (byte) 0x04, (byte) 0x05, (byte) 0x30, (byte) 0x03,
799             (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x30, (byte) 0x0d, (byte) 0x06,
800             (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7,
801             (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x00,
802             (byte) 0x03, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0x08, (byte) 0x7f,
803             (byte) 0x6a, (byte) 0x48, (byte) 0x90, (byte) 0x7b, (byte) 0x9b, (byte) 0x72,
804             (byte) 0x13, (byte) 0xa7, (byte) 0xef, (byte) 0x6b, (byte) 0x0b, (byte) 0x59,
805             (byte) 0xe5, (byte) 0x49, (byte) 0x72, (byte) 0x3a, (byte) 0xc8, (byte) 0x84,
806             (byte) 0xcc, (byte) 0x23, (byte) 0x18, (byte) 0x4c, (byte) 0xec, (byte) 0xc7,
807             (byte) 0xef, (byte) 0xcb, (byte) 0xa7, (byte) 0xbe, (byte) 0xe4, (byte) 0xef,
808             (byte) 0x8f, (byte) 0xc6, (byte) 0x06, (byte) 0x8c, (byte) 0xc0, (byte) 0xe4,
809             (byte) 0x2f, (byte) 0x2a, (byte) 0xc0, (byte) 0x35, (byte) 0x7d, (byte) 0x5e,
810             (byte) 0x19, (byte) 0x29, (byte) 0x8c, (byte) 0xb9, (byte) 0xf1, (byte) 0x1e,
811             (byte) 0xaf, (byte) 0x82, (byte) 0xd8, (byte) 0xe3, (byte) 0x88, (byte) 0xe1,
812             (byte) 0x31, (byte) 0xc8, (byte) 0x82, (byte) 0x1f, (byte) 0x83, (byte) 0xa9,
813             (byte) 0xde, (byte) 0xfe, (byte) 0x4b, (byte) 0xe2, (byte) 0x78, (byte) 0x64,
814             (byte) 0xed, (byte) 0xa4, (byte) 0x7b, (byte) 0xee, (byte) 0x8d, (byte) 0x71,
815             (byte) 0x1b, (byte) 0x44, (byte) 0xe6, (byte) 0xb7, (byte) 0xe8, (byte) 0xc5,
816             (byte) 0x9a, (byte) 0x93, (byte) 0x92, (byte) 0x6f, (byte) 0x6f, (byte) 0xdb,
817             (byte) 0xbd, (byte) 0xd7, (byte) 0x03, (byte) 0x85, (byte) 0xa9, (byte) 0x5f,
818             (byte) 0x53, (byte) 0x5f, (byte) 0x5d, (byte) 0x30, (byte) 0xc6, (byte) 0xd9,
819             (byte) 0xce, (byte) 0x34, (byte) 0xa8, (byte) 0xbe, (byte) 0x31, (byte) 0x47,
820             (byte) 0x1c, (byte) 0xa4, (byte) 0x7f, (byte) 0xc0, (byte) 0x2c, (byte) 0xbc,
821             (byte) 0xfe, (byte) 0x1a, (byte) 0x31, (byte) 0xd8, (byte) 0x77, (byte) 0x4d,
822             (byte) 0xfc, (byte) 0x45, (byte) 0x84, (byte) 0xfc, (byte) 0x45, (byte) 0x12,
823             (byte) 0xab, (byte) 0x50, (byte) 0xe4, (byte) 0x45, (byte) 0xe5, (byte) 0x11
824     };
825 
826     /**
827      * Generated from above and converted with: openssl pkcs8 -topk8 -outform d
828      * -in userkey.pem -nocrypt | xxd -i | sed 's/0x/(byte) 0x/g'
829      */
830     private static final byte[] FAKE_DSA_KEY_1 = new byte[] {
831             (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x4c, (byte) 0x02, (byte) 0x01,
832             (byte) 0x00, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x2c, (byte) 0x06,
833             (byte) 0x07, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x38,
834             (byte) 0x04, (byte) 0x01, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x1f,
835             (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xb3, (byte) 0x23,
836             (byte) 0xf7, (byte) 0x86, (byte) 0xbd, (byte) 0x3b, (byte) 0x86, (byte) 0xcc,
837             (byte) 0xc3, (byte) 0x91, (byte) 0xc0, (byte) 0x30, (byte) 0x32, (byte) 0x02,
838             (byte) 0x47, (byte) 0x35, (byte) 0x01, (byte) 0xef, (byte) 0xee, (byte) 0x98,
839             (byte) 0x13, (byte) 0x56, (byte) 0x49, (byte) 0x47, (byte) 0xb5, (byte) 0x20,
840             (byte) 0xa8, (byte) 0x60, (byte) 0xcb, (byte) 0xc0, (byte) 0xd5, (byte) 0x77,
841             (byte) 0xc1, (byte) 0x69, (byte) 0xcd, (byte) 0x18, (byte) 0x34, (byte) 0x92,
842             (byte) 0xf2, (byte) 0x6a, (byte) 0x2a, (byte) 0x10, (byte) 0x59, (byte) 0x1c,
843             (byte) 0x91, (byte) 0x20, (byte) 0x51, (byte) 0xca, (byte) 0x37, (byte) 0xb2,
844             (byte) 0x87, (byte) 0xa6, (byte) 0x8a, (byte) 0x02, (byte) 0xfd, (byte) 0x45,
845             (byte) 0x46, (byte) 0xf9, (byte) 0x76, (byte) 0xb1, (byte) 0x35, (byte) 0x38,
846             (byte) 0x8d, (byte) 0xff, (byte) 0x4c, (byte) 0x5d, (byte) 0x75, (byte) 0x8f,
847             (byte) 0x66, (byte) 0x15, (byte) 0x7d, (byte) 0x7b, (byte) 0xda, (byte) 0xdb,
848             (byte) 0x57, (byte) 0x39, (byte) 0xff, (byte) 0x91, (byte) 0x3f, (byte) 0xdd,
849             (byte) 0xe2, (byte) 0xb4, (byte) 0x22, (byte) 0x60, (byte) 0x4c, (byte) 0x32,
850             (byte) 0x3b, (byte) 0x9d, (byte) 0x34, (byte) 0x9f, (byte) 0xb9, (byte) 0x5d,
851             (byte) 0x75, (byte) 0xb9, (byte) 0xd3, (byte) 0x7f, (byte) 0x11, (byte) 0xba,
852             (byte) 0xb7, (byte) 0xc8, (byte) 0x32, (byte) 0xc6, (byte) 0xce, (byte) 0x71,
853             (byte) 0x91, (byte) 0xd3, (byte) 0x32, (byte) 0xaf, (byte) 0x4d, (byte) 0x7e,
854             (byte) 0x7c, (byte) 0x15, (byte) 0xf7, (byte) 0x71, (byte) 0x2c, (byte) 0x52,
855             (byte) 0x65, (byte) 0x4d, (byte) 0xa9, (byte) 0x81, (byte) 0x25, (byte) 0x35,
856             (byte) 0xce, (byte) 0x0b, (byte) 0x5b, (byte) 0x56, (byte) 0xfe, (byte) 0xf1,
857             (byte) 0x02, (byte) 0x15, (byte) 0x00, (byte) 0xeb, (byte) 0x4e, (byte) 0x7f,
858             (byte) 0x7a, (byte) 0x31, (byte) 0xb3, (byte) 0x7d, (byte) 0x8d, (byte) 0xb2,
859             (byte) 0xf7, (byte) 0xaf, (byte) 0xad, (byte) 0xb1, (byte) 0x42, (byte) 0x92,
860             (byte) 0xf3, (byte) 0x6c, (byte) 0xe4, (byte) 0xed, (byte) 0x8b, (byte) 0x02,
861             (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0x81, (byte) 0xc8, (byte) 0x36,
862             (byte) 0x48, (byte) 0xdb, (byte) 0x71, (byte) 0x2b, (byte) 0x91, (byte) 0xce,
863             (byte) 0x6d, (byte) 0xbc, (byte) 0xb8, (byte) 0xf9, (byte) 0xcb, (byte) 0x50,
864             (byte) 0x91, (byte) 0x10, (byte) 0x8a, (byte) 0xf8, (byte) 0x37, (byte) 0x50,
865             (byte) 0xda, (byte) 0x4f, (byte) 0xc8, (byte) 0x4d, (byte) 0x73, (byte) 0xcb,
866             (byte) 0x4d, (byte) 0xb0, (byte) 0x19, (byte) 0x54, (byte) 0x5a, (byte) 0xf3,
867             (byte) 0x6c, (byte) 0xc9, (byte) 0xd8, (byte) 0x96, (byte) 0xd9, (byte) 0xb0,
868             (byte) 0x54, (byte) 0x7e, (byte) 0x7d, (byte) 0xe2, (byte) 0x58, (byte) 0x0e,
869             (byte) 0x5f, (byte) 0xc0, (byte) 0xce, (byte) 0xb9, (byte) 0x5c, (byte) 0xe3,
870             (byte) 0xd3, (byte) 0xdf, (byte) 0xcf, (byte) 0x45, (byte) 0x74, (byte) 0xfb,
871             (byte) 0xe6, (byte) 0x20, (byte) 0xe7, (byte) 0xfc, (byte) 0x0f, (byte) 0xca,
872             (byte) 0xdb, (byte) 0xc0, (byte) 0x0b, (byte) 0xe1, (byte) 0x5a, (byte) 0x16,
873             (byte) 0x1d, (byte) 0xb3, (byte) 0x2e, (byte) 0xe5, (byte) 0x5f, (byte) 0x89,
874             (byte) 0x17, (byte) 0x73, (byte) 0x50, (byte) 0xd1, (byte) 0x4a, (byte) 0x60,
875             (byte) 0xb7, (byte) 0xaa, (byte) 0xf0, (byte) 0xc7, (byte) 0xc5, (byte) 0x03,
876             (byte) 0x4e, (byte) 0x36, (byte) 0x51, (byte) 0x9e, (byte) 0x2f, (byte) 0xfa,
877             (byte) 0xf3, (byte) 0xd6, (byte) 0x58, (byte) 0x14, (byte) 0x02, (byte) 0xb4,
878             (byte) 0x41, (byte) 0xd6, (byte) 0x72, (byte) 0x6f, (byte) 0x58, (byte) 0x5b,
879             (byte) 0x2d, (byte) 0x23, (byte) 0xc0, (byte) 0x75, (byte) 0x4f, (byte) 0x39,
880             (byte) 0xa8, (byte) 0x6a, (byte) 0xdf, (byte) 0x79, (byte) 0x21, (byte) 0xf2,
881             (byte) 0x77, (byte) 0x91, (byte) 0x3f, (byte) 0x1c, (byte) 0x4d, (byte) 0x48,
882             (byte) 0x78, (byte) 0xcd, (byte) 0xed, (byte) 0x79, (byte) 0x23, (byte) 0x04,
883             (byte) 0x17, (byte) 0x02, (byte) 0x15, (byte) 0x00, (byte) 0xc7, (byte) 0xe7,
884             (byte) 0xe2, (byte) 0x6b, (byte) 0x14, (byte) 0xe6, (byte) 0x31, (byte) 0x12,
885             (byte) 0xb2, (byte) 0x1e, (byte) 0xd4, (byte) 0xf2, (byte) 0x9b, (byte) 0x2c,
886             (byte) 0xf6, (byte) 0x54, (byte) 0x4c, (byte) 0x12, (byte) 0xe8, (byte) 0x22
887     };
888 
889     /**
890      * Generated from above and converted with: openssl x509 -outform d -in
891      * usercert.pem | xxd -i | sed 's/0x/(byte) 0x/g'
892      */
893     private static final byte[] FAKE_DSA_USER_1 = new byte[] {
894             (byte) 0x30, (byte) 0x82, (byte) 0x03, (byte) 0xca, (byte) 0x30, (byte) 0x82,
895             (byte) 0x03, (byte) 0x33, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01,
896             (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x0d,
897             (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
898             (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05,
899             (byte) 0x00, (byte) 0x30, (byte) 0x5e, (byte) 0x31, (byte) 0x0b, (byte) 0x30,
900             (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06,
901             (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55, (byte) 0x31, (byte) 0x13,
902             (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04,
903             (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x6d,
904             (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x74,
905             (byte) 0x65, (byte) 0x31, (byte) 0x21, (byte) 0x30, (byte) 0x1f, (byte) 0x06,
906             (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x18,
907             (byte) 0x49, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e,
908             (byte) 0x65, (byte) 0x74, (byte) 0x20, (byte) 0x57, (byte) 0x69, (byte) 0x64,
909             (byte) 0x67, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x20, (byte) 0x50,
910             (byte) 0x74, (byte) 0x79, (byte) 0x20, (byte) 0x4c, (byte) 0x74, (byte) 0x64,
911             (byte) 0x31, (byte) 0x17, (byte) 0x30, (byte) 0x15, (byte) 0x06, (byte) 0x03,
912             (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x0e, (byte) 0x63,
913             (byte) 0x61, (byte) 0x2e, (byte) 0x65, (byte) 0x78, (byte) 0x61, (byte) 0x6d,
914             (byte) 0x70, (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f,
915             (byte) 0x6d, (byte) 0x30, (byte) 0x1e, (byte) 0x17, (byte) 0x0d, (byte) 0x31,
916             (byte) 0x33, (byte) 0x30, (byte) 0x38, (byte) 0x32, (byte) 0x37, (byte) 0x32,
917             (byte) 0x33, (byte) 0x33, (byte) 0x34, (byte) 0x32, (byte) 0x32, (byte) 0x5a,
918             (byte) 0x17, (byte) 0x0d, (byte) 0x32, (byte) 0x33, (byte) 0x30, (byte) 0x38,
919             (byte) 0x32, (byte) 0x35, (byte) 0x32, (byte) 0x33, (byte) 0x33, (byte) 0x34,
920             (byte) 0x32, (byte) 0x32, (byte) 0x5a, (byte) 0x30, (byte) 0x62, (byte) 0x31,
921             (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55,
922             (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55,
923             (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03,
924             (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53,
925             (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74,
926             (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x21, (byte) 0x30,
927             (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a,
928             (byte) 0x0c, (byte) 0x18, (byte) 0x49, (byte) 0x6e, (byte) 0x74, (byte) 0x65,
929             (byte) 0x72, (byte) 0x6e, (byte) 0x65, (byte) 0x74, (byte) 0x20, (byte) 0x57,
930             (byte) 0x69, (byte) 0x64, (byte) 0x67, (byte) 0x69, (byte) 0x74, (byte) 0x73,
931             (byte) 0x20, (byte) 0x50, (byte) 0x74, (byte) 0x79, (byte) 0x20, (byte) 0x4c,
932             (byte) 0x74, (byte) 0x64, (byte) 0x31, (byte) 0x1b, (byte) 0x30, (byte) 0x19,
933             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c,
934             (byte) 0x12, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x65,
935             (byte) 0x72, (byte) 0x2e, (byte) 0x65, (byte) 0x78, (byte) 0x61, (byte) 0x6d,
936             (byte) 0x70, (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f,
937             (byte) 0x6d, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0xb7, (byte) 0x30,
938             (byte) 0x82, (byte) 0x01, (byte) 0x2c, (byte) 0x06, (byte) 0x07, (byte) 0x2a,
939             (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x38, (byte) 0x04, (byte) 0x01,
940             (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0x1f, (byte) 0x02, (byte) 0x81,
941             (byte) 0x81, (byte) 0x00, (byte) 0xb3, (byte) 0x23, (byte) 0xf7, (byte) 0x86,
942             (byte) 0xbd, (byte) 0x3b, (byte) 0x86, (byte) 0xcc, (byte) 0xc3, (byte) 0x91,
943             (byte) 0xc0, (byte) 0x30, (byte) 0x32, (byte) 0x02, (byte) 0x47, (byte) 0x35,
944             (byte) 0x01, (byte) 0xef, (byte) 0xee, (byte) 0x98, (byte) 0x13, (byte) 0x56,
945             (byte) 0x49, (byte) 0x47, (byte) 0xb5, (byte) 0x20, (byte) 0xa8, (byte) 0x60,
946             (byte) 0xcb, (byte) 0xc0, (byte) 0xd5, (byte) 0x77, (byte) 0xc1, (byte) 0x69,
947             (byte) 0xcd, (byte) 0x18, (byte) 0x34, (byte) 0x92, (byte) 0xf2, (byte) 0x6a,
948             (byte) 0x2a, (byte) 0x10, (byte) 0x59, (byte) 0x1c, (byte) 0x91, (byte) 0x20,
949             (byte) 0x51, (byte) 0xca, (byte) 0x37, (byte) 0xb2, (byte) 0x87, (byte) 0xa6,
950             (byte) 0x8a, (byte) 0x02, (byte) 0xfd, (byte) 0x45, (byte) 0x46, (byte) 0xf9,
951             (byte) 0x76, (byte) 0xb1, (byte) 0x35, (byte) 0x38, (byte) 0x8d, (byte) 0xff,
952             (byte) 0x4c, (byte) 0x5d, (byte) 0x75, (byte) 0x8f, (byte) 0x66, (byte) 0x15,
953             (byte) 0x7d, (byte) 0x7b, (byte) 0xda, (byte) 0xdb, (byte) 0x57, (byte) 0x39,
954             (byte) 0xff, (byte) 0x91, (byte) 0x3f, (byte) 0xdd, (byte) 0xe2, (byte) 0xb4,
955             (byte) 0x22, (byte) 0x60, (byte) 0x4c, (byte) 0x32, (byte) 0x3b, (byte) 0x9d,
956             (byte) 0x34, (byte) 0x9f, (byte) 0xb9, (byte) 0x5d, (byte) 0x75, (byte) 0xb9,
957             (byte) 0xd3, (byte) 0x7f, (byte) 0x11, (byte) 0xba, (byte) 0xb7, (byte) 0xc8,
958             (byte) 0x32, (byte) 0xc6, (byte) 0xce, (byte) 0x71, (byte) 0x91, (byte) 0xd3,
959             (byte) 0x32, (byte) 0xaf, (byte) 0x4d, (byte) 0x7e, (byte) 0x7c, (byte) 0x15,
960             (byte) 0xf7, (byte) 0x71, (byte) 0x2c, (byte) 0x52, (byte) 0x65, (byte) 0x4d,
961             (byte) 0xa9, (byte) 0x81, (byte) 0x25, (byte) 0x35, (byte) 0xce, (byte) 0x0b,
962             (byte) 0x5b, (byte) 0x56, (byte) 0xfe, (byte) 0xf1, (byte) 0x02, (byte) 0x15,
963             (byte) 0x00, (byte) 0xeb, (byte) 0x4e, (byte) 0x7f, (byte) 0x7a, (byte) 0x31,
964             (byte) 0xb3, (byte) 0x7d, (byte) 0x8d, (byte) 0xb2, (byte) 0xf7, (byte) 0xaf,
965             (byte) 0xad, (byte) 0xb1, (byte) 0x42, (byte) 0x92, (byte) 0xf3, (byte) 0x6c,
966             (byte) 0xe4, (byte) 0xed, (byte) 0x8b, (byte) 0x02, (byte) 0x81, (byte) 0x81,
967             (byte) 0x00, (byte) 0x81, (byte) 0xc8, (byte) 0x36, (byte) 0x48, (byte) 0xdb,
968             (byte) 0x71, (byte) 0x2b, (byte) 0x91, (byte) 0xce, (byte) 0x6d, (byte) 0xbc,
969             (byte) 0xb8, (byte) 0xf9, (byte) 0xcb, (byte) 0x50, (byte) 0x91, (byte) 0x10,
970             (byte) 0x8a, (byte) 0xf8, (byte) 0x37, (byte) 0x50, (byte) 0xda, (byte) 0x4f,
971             (byte) 0xc8, (byte) 0x4d, (byte) 0x73, (byte) 0xcb, (byte) 0x4d, (byte) 0xb0,
972             (byte) 0x19, (byte) 0x54, (byte) 0x5a, (byte) 0xf3, (byte) 0x6c, (byte) 0xc9,
973             (byte) 0xd8, (byte) 0x96, (byte) 0xd9, (byte) 0xb0, (byte) 0x54, (byte) 0x7e,
974             (byte) 0x7d, (byte) 0xe2, (byte) 0x58, (byte) 0x0e, (byte) 0x5f, (byte) 0xc0,
975             (byte) 0xce, (byte) 0xb9, (byte) 0x5c, (byte) 0xe3, (byte) 0xd3, (byte) 0xdf,
976             (byte) 0xcf, (byte) 0x45, (byte) 0x74, (byte) 0xfb, (byte) 0xe6, (byte) 0x20,
977             (byte) 0xe7, (byte) 0xfc, (byte) 0x0f, (byte) 0xca, (byte) 0xdb, (byte) 0xc0,
978             (byte) 0x0b, (byte) 0xe1, (byte) 0x5a, (byte) 0x16, (byte) 0x1d, (byte) 0xb3,
979             (byte) 0x2e, (byte) 0xe5, (byte) 0x5f, (byte) 0x89, (byte) 0x17, (byte) 0x73,
980             (byte) 0x50, (byte) 0xd1, (byte) 0x4a, (byte) 0x60, (byte) 0xb7, (byte) 0xaa,
981             (byte) 0xf0, (byte) 0xc7, (byte) 0xc5, (byte) 0x03, (byte) 0x4e, (byte) 0x36,
982             (byte) 0x51, (byte) 0x9e, (byte) 0x2f, (byte) 0xfa, (byte) 0xf3, (byte) 0xd6,
983             (byte) 0x58, (byte) 0x14, (byte) 0x02, (byte) 0xb4, (byte) 0x41, (byte) 0xd6,
984             (byte) 0x72, (byte) 0x6f, (byte) 0x58, (byte) 0x5b, (byte) 0x2d, (byte) 0x23,
985             (byte) 0xc0, (byte) 0x75, (byte) 0x4f, (byte) 0x39, (byte) 0xa8, (byte) 0x6a,
986             (byte) 0xdf, (byte) 0x79, (byte) 0x21, (byte) 0xf2, (byte) 0x77, (byte) 0x91,
987             (byte) 0x3f, (byte) 0x1c, (byte) 0x4d, (byte) 0x48, (byte) 0x78, (byte) 0xcd,
988             (byte) 0xed, (byte) 0x79, (byte) 0x23, (byte) 0x03, (byte) 0x81, (byte) 0x84,
989             (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x1a, (byte) 0x50,
990             (byte) 0x9d, (byte) 0x3e, (byte) 0xa1, (byte) 0x6c, (byte) 0x99, (byte) 0x35,
991             (byte) 0x36, (byte) 0x26, (byte) 0x22, (byte) 0x6b, (byte) 0x47, (byte) 0x45,
992             (byte) 0x80, (byte) 0x5b, (byte) 0xd5, (byte) 0xc1, (byte) 0xc5, (byte) 0x70,
993             (byte) 0x75, (byte) 0x55, (byte) 0x66, (byte) 0x33, (byte) 0x1d, (byte) 0xae,
994             (byte) 0xd0, (byte) 0x01, (byte) 0x64, (byte) 0x8b, (byte) 0xae, (byte) 0x9d,
995             (byte) 0x66, (byte) 0x58, (byte) 0xf9, (byte) 0x42, (byte) 0x74, (byte) 0x3a,
996             (byte) 0x32, (byte) 0xc7, (byte) 0x7f, (byte) 0x25, (byte) 0x64, (byte) 0x7d,
997             (byte) 0x08, (byte) 0x26, (byte) 0xbf, (byte) 0x21, (byte) 0x3a, (byte) 0x84,
998             (byte) 0xcc, (byte) 0x2c, (byte) 0x66, (byte) 0x7d, (byte) 0xc7, (byte) 0xd6,
999             (byte) 0xb1, (byte) 0x69, (byte) 0x57, (byte) 0x67, (byte) 0x52, (byte) 0x73,
1000             (byte) 0x3f, (byte) 0x79, (byte) 0x60, (byte) 0xaa, (byte) 0xf4, (byte) 0x8a,
1001             (byte) 0x48, (byte) 0x42, (byte) 0x46, (byte) 0x41, (byte) 0xd0, (byte) 0x50,
1002             (byte) 0x9b, (byte) 0xa2, (byte) 0x4e, (byte) 0xa5, (byte) 0x88, (byte) 0x10,
1003             (byte) 0xf7, (byte) 0x61, (byte) 0xa2, (byte) 0xfa, (byte) 0x8d, (byte) 0xa6,
1004             (byte) 0x13, (byte) 0x9e, (byte) 0x36, (byte) 0x86, (byte) 0x62, (byte) 0xf0,
1005             (byte) 0x97, (byte) 0xef, (byte) 0x11, (byte) 0xc6, (byte) 0x35, (byte) 0xd3,
1006             (byte) 0x79, (byte) 0x30, (byte) 0xde, (byte) 0xf2, (byte) 0x7f, (byte) 0x7a,
1007             (byte) 0x3c, (byte) 0x03, (byte) 0xa3, (byte) 0xc5, (byte) 0xbc, (byte) 0xb1,
1008             (byte) 0xbc, (byte) 0x2f, (byte) 0x10, (byte) 0xf4, (byte) 0x51, (byte) 0x89,
1009             (byte) 0xe2, (byte) 0xaf, (byte) 0xf7, (byte) 0x61, (byte) 0x1a, (byte) 0xf0,
1010             (byte) 0x87, (byte) 0x5e, (byte) 0xa5, (byte) 0x02, (byte) 0xd2, (byte) 0xe4,
1011             (byte) 0xa3, (byte) 0x7b, (byte) 0x30, (byte) 0x79, (byte) 0x30, (byte) 0x09,
1012             (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13, (byte) 0x04,
1013             (byte) 0x02, (byte) 0x30, (byte) 0x00, (byte) 0x30, (byte) 0x2c, (byte) 0x06,
1014             (byte) 0x09, (byte) 0x60, (byte) 0x86, (byte) 0x48, (byte) 0x01, (byte) 0x86,
1015             (byte) 0xf8, (byte) 0x42, (byte) 0x01, (byte) 0x0d, (byte) 0x04, (byte) 0x1f,
1016             (byte) 0x16, (byte) 0x1d, (byte) 0x4f, (byte) 0x70, (byte) 0x65, (byte) 0x6e,
1017             (byte) 0x53, (byte) 0x53, (byte) 0x4c, (byte) 0x20, (byte) 0x47, (byte) 0x65,
1018             (byte) 0x6e, (byte) 0x65, (byte) 0x72, (byte) 0x61, (byte) 0x74, (byte) 0x65,
1019             (byte) 0x64, (byte) 0x20, (byte) 0x43, (byte) 0x65, (byte) 0x72, (byte) 0x74,
1020             (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61, (byte) 0x74,
1021             (byte) 0x65, (byte) 0x30, (byte) 0x1d, (byte) 0x06, (byte) 0x03, (byte) 0x55,
1022             (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16, (byte) 0x04, (byte) 0x14,
1023             (byte) 0xd1, (byte) 0x6c, (byte) 0x36, (byte) 0x36, (byte) 0x61, (byte) 0x6c,
1024             (byte) 0xf6, (byte) 0x90, (byte) 0x82, (byte) 0x82, (byte) 0x87, (byte) 0x93,
1025             (byte) 0xbe, (byte) 0x99, (byte) 0x60, (byte) 0x1b, (byte) 0x03, (byte) 0x58,
1026             (byte) 0x36, (byte) 0x63, (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03,
1027             (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, (byte) 0x18, (byte) 0x30,
1028             (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0x47, (byte) 0x82, (byte) 0xa3,
1029             (byte) 0xf1, (byte) 0xc2, (byte) 0x7e, (byte) 0x3a, (byte) 0xde, (byte) 0x4f,
1030             (byte) 0x30, (byte) 0x4c, (byte) 0x7f, (byte) 0x72, (byte) 0x81, (byte) 0x15,
1031             (byte) 0x32, (byte) 0xda, (byte) 0x7f, (byte) 0x58, (byte) 0x18, (byte) 0x30,
1032             (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48,
1033             (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05,
1034             (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0x81, (byte) 0x00,
1035             (byte) 0x81, (byte) 0xde, (byte) 0x20, (byte) 0xa1, (byte) 0xb2, (byte) 0x50,
1036             (byte) 0x03, (byte) 0xcd, (byte) 0x90, (byte) 0x4f, (byte) 0x2b, (byte) 0x47,
1037             (byte) 0x1d, (byte) 0xac, (byte) 0x6e, (byte) 0xb4, (byte) 0xc7, (byte) 0x14,
1038             (byte) 0xc6, (byte) 0x4f, (byte) 0x45, (byte) 0xaf, (byte) 0x81, (byte) 0x5d,
1039             (byte) 0x5a, (byte) 0x31, (byte) 0xff, (byte) 0x9c, (byte) 0x4d, (byte) 0xdc,
1040             (byte) 0x9e, (byte) 0x36, (byte) 0x9f, (byte) 0x9b, (byte) 0xb1, (byte) 0xc9,
1041             (byte) 0x50, (byte) 0xa3, (byte) 0xf6, (byte) 0x9c, (byte) 0x68, (byte) 0x6f,
1042             (byte) 0x68, (byte) 0xd9, (byte) 0x56, (byte) 0x1b, (byte) 0xe5, (byte) 0x1b,
1043             (byte) 0x41, (byte) 0xd4, (byte) 0xcc, (byte) 0xb6, (byte) 0x37, (byte) 0xd5,
1044             (byte) 0x69, (byte) 0x6b, (byte) 0x39, (byte) 0xaf, (byte) 0xc6, (byte) 0xb8,
1045             (byte) 0x39, (byte) 0x76, (byte) 0xe3, (byte) 0xf7, (byte) 0x97, (byte) 0x74,
1046             (byte) 0x31, (byte) 0xc4, (byte) 0x2d, (byte) 0xb7, (byte) 0x9a, (byte) 0xa4,
1047             (byte) 0xfa, (byte) 0x9f, (byte) 0xa8, (byte) 0xe3, (byte) 0x41, (byte) 0xda,
1048             (byte) 0x2f, (byte) 0x0c, (byte) 0x9d, (byte) 0x83, (byte) 0xdc, (byte) 0x86,
1049             (byte) 0x1f, (byte) 0x5c, (byte) 0x0f, (byte) 0x87, (byte) 0x05, (byte) 0xc9,
1050             (byte) 0xb0, (byte) 0x63, (byte) 0xca, (byte) 0x9b, (byte) 0xdb, (byte) 0xe6,
1051             (byte) 0x3c, (byte) 0xe9, (byte) 0x23, (byte) 0x9e, (byte) 0x23, (byte) 0x44,
1052             (byte) 0x1d, (byte) 0x5b, (byte) 0x60, (byte) 0x66, (byte) 0xb6, (byte) 0x72,
1053             (byte) 0x8c, (byte) 0x87, (byte) 0x86, (byte) 0xe8, (byte) 0xdb, (byte) 0x29,
1054             (byte) 0x67, (byte) 0x9c, (byte) 0x33, (byte) 0x5c, (byte) 0x39, (byte) 0xf1,
1055             (byte) 0xb5, (byte) 0x9b, (byte) 0xb8, (byte) 0xe1, (byte) 0x42, (byte) 0x51,
1056             (byte) 0xed, (byte) 0x2c
1057     };
1058 
1059     /**
1060      * The amount of time to allow before and after expected time for variance
1061      * in timing tests.
1062      */
1063     private static final long SLOP_TIME_MILLIS = 15000L;
1064 
1065     @Override
setUp()1066     protected void setUp() throws Exception {
1067         // Wipe any existing entries in the KeyStore
1068         KeyStore ksTemp = KeyStore.getInstance("AndroidKeyStore");
1069         ksTemp.load(null, null);
1070         Enumeration<String> aliases = ksTemp.aliases();
1071         while (aliases.hasMoreElements()) {
1072             String alias = aliases.nextElement();
1073             ksTemp.deleteEntry(alias);
1074         }
1075 
1076         // Get a new instance because some tests need it uninitialized
1077         mKeyStore = KeyStore.getInstance("AndroidKeyStore");
1078     }
1079 
generatePrivateKey(String keyType, byte[] fakeKey1)1080     private PrivateKey generatePrivateKey(String keyType, byte[] fakeKey1) throws Exception {
1081         KeyFactory kf = KeyFactory.getInstance(keyType);
1082         return kf.generatePrivate(new PKCS8EncodedKeySpec(fakeKey1));
1083     }
1084 
generateCertificate(byte[] fakeUser1)1085     private Certificate generateCertificate(byte[] fakeUser1) throws Exception {
1086         CertificateFactory cf = CertificateFactory.getInstance("X.509");
1087         return cf.generateCertificate(new ByteArrayInputStream(fakeUser1));
1088     }
1089 
makeUserDsaKey1()1090     private PrivateKeyEntry makeUserDsaKey1() throws Exception {
1091         return new KeyStore.PrivateKeyEntry(generatePrivateKey("DSA", FAKE_DSA_KEY_1),
1092                 new Certificate[] {
1093                 generateCertificate(FAKE_DSA_USER_1), generateCertificate(FAKE_DSA_CA_1)
1094         });
1095     }
1096 
makeUserEcKey1()1097     private PrivateKeyEntry makeUserEcKey1() throws Exception {
1098         return new KeyStore.PrivateKeyEntry(generatePrivateKey("EC", FAKE_EC_KEY_1),
1099                 new Certificate[] {
1100                         generateCertificate(FAKE_EC_USER_1), generateCertificate(FAKE_EC_CA_1)
1101                 });
1102     }
1103 
makeUserRsaKey1()1104     private PrivateKeyEntry makeUserRsaKey1() throws Exception {
1105         return new KeyStore.PrivateKeyEntry(generatePrivateKey("RSA", FAKE_RSA_KEY_1),
1106                 new Certificate[] {
1107                         generateCertificate(FAKE_RSA_USER_1), generateCertificate(FAKE_RSA_CA_1)
1108                 });
1109     }
1110 
makeCa1()1111     private Entry makeCa1() throws Exception {
1112         return new KeyStore.TrustedCertificateEntry(generateCertificate(FAKE_RSA_CA_1));
1113     }
1114 
assertAliases(final String[] expectedAliases)1115     private void assertAliases(final String[] expectedAliases) throws KeyStoreException {
1116         final Enumeration<String> aliases = mKeyStore.aliases();
1117         int count = 0;
1118 
1119         final Set<String> expectedSet = new HashSet<String>();
1120         expectedSet.addAll(Arrays.asList(expectedAliases));
1121 
1122         while (aliases.hasMoreElements()) {
1123             count++;
1124             final String alias = aliases.nextElement();
1125             assertTrue("The alias should be in the expected set", expectedSet.contains(alias));
1126             expectedSet.remove(alias);
1127         }
1128         assertTrue("The expected set and actual set should be exactly equal", expectedSet.isEmpty());
1129         assertEquals("There should be the correct number of keystore entries",
1130                 expectedAliases.length, count);
1131     }
1132 
testKeyStore_Aliases_Unencrypted_Success()1133     public void testKeyStore_Aliases_Unencrypted_Success() throws Exception {
1134         mKeyStore.load(null, null);
1135 
1136         assertAliases(new String[] {});
1137 
1138         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1139 
1140         assertAliases(new String[] { TEST_ALIAS_1 });
1141 
1142         mKeyStore.setEntry(TEST_ALIAS_2, makeCa1(), null);
1143 
1144         assertAliases(new String[] { TEST_ALIAS_1, TEST_ALIAS_2 });
1145     }
1146 
testKeyStore_Aliases_NotInitialized_Unencrypted_Failure()1147     public void testKeyStore_Aliases_NotInitialized_Unencrypted_Failure() throws Exception {
1148         try {
1149             mKeyStore.aliases();
1150             fail("KeyStore should throw exception when not initialized");
1151         } catch (KeyStoreException success) {
1152         }
1153     }
1154 
testKeyStore_ContainsAliases_PrivateAndCA_Unencrypted_Success()1155     public void testKeyStore_ContainsAliases_PrivateAndCA_Unencrypted_Success() throws Exception {
1156         mKeyStore.load(null, null);
1157 
1158         assertAliases(new String[] {});
1159 
1160         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1161 
1162         assertTrue("Should contain generated private key", mKeyStore.containsAlias(TEST_ALIAS_1));
1163 
1164         mKeyStore.setEntry(TEST_ALIAS_2, makeCa1(), null);
1165 
1166         assertTrue("Should contain added CA certificate", mKeyStore.containsAlias(TEST_ALIAS_2));
1167 
1168         assertFalse("Should not contain unadded certificate alias",
1169                 mKeyStore.containsAlias(TEST_ALIAS_3));
1170     }
1171 
testKeyStore_ContainsAliases_CAOnly_Unencrypted_Success()1172     public void testKeyStore_ContainsAliases_CAOnly_Unencrypted_Success() throws Exception {
1173         mKeyStore.load(null, null);
1174 
1175         mKeyStore.setEntry(TEST_ALIAS_2, makeCa1(), null);
1176 
1177         assertTrue("Should contain added CA certificate", mKeyStore.containsAlias(TEST_ALIAS_2));
1178     }
1179 
testKeyStore_ContainsAliases_NonExistent_Unencrypted_Failure()1180     public void testKeyStore_ContainsAliases_NonExistent_Unencrypted_Failure() throws Exception {
1181         mKeyStore.load(null, null);
1182 
1183         assertFalse("Should contain added CA certificate", mKeyStore.containsAlias(TEST_ALIAS_1));
1184     }
1185 
testKeyStore_DeleteEntry_Unencrypted_Success()1186     public void testKeyStore_DeleteEntry_Unencrypted_Success() throws Exception {
1187         mKeyStore.load(null, null);
1188 
1189         // TEST_ALIAS_1
1190         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1191 
1192         // TEST_ALIAS_2
1193         mKeyStore.setCertificateEntry(TEST_ALIAS_2, generateCertificate(FAKE_RSA_CA_1));
1194 
1195         // TEST_ALIAS_3
1196         mKeyStore.setCertificateEntry(TEST_ALIAS_3, generateCertificate(FAKE_RSA_CA_1));
1197 
1198         assertAliases(new String[] { TEST_ALIAS_1, TEST_ALIAS_2, TEST_ALIAS_3 });
1199 
1200         mKeyStore.deleteEntry(TEST_ALIAS_1);
1201 
1202         assertAliases(new String[] { TEST_ALIAS_2, TEST_ALIAS_3 });
1203 
1204         mKeyStore.deleteEntry(TEST_ALIAS_3);
1205 
1206         assertAliases(new String[] { TEST_ALIAS_2 });
1207 
1208         mKeyStore.deleteEntry(TEST_ALIAS_2);
1209 
1210         assertAliases(new String[] { });
1211     }
1212 
testKeyStore_DeleteEntry_EmptyStore_Unencrypted_Success()1213     public void testKeyStore_DeleteEntry_EmptyStore_Unencrypted_Success() throws Exception {
1214         mKeyStore.load(null, null);
1215 
1216         // Should not throw when a non-existent entry is requested for delete.
1217         mKeyStore.deleteEntry(TEST_ALIAS_1);
1218     }
1219 
testKeyStore_DeleteEntry_NonExistent_Unencrypted_Success()1220     public void testKeyStore_DeleteEntry_NonExistent_Unencrypted_Success() throws Exception {
1221         mKeyStore.load(null, null);
1222 
1223         // TEST_ALIAS_1
1224         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1225 
1226         // Should not throw when a non-existent entry is requested for delete.
1227         mKeyStore.deleteEntry(TEST_ALIAS_2);
1228     }
1229 
testKeyStore_GetCertificate_Single_Unencrypted_Success()1230     public void testKeyStore_GetCertificate_Single_Unencrypted_Success() throws Exception {
1231         mKeyStore.load(null, null);
1232 
1233         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
1234 
1235         assertAliases(new String[] { TEST_ALIAS_1 });
1236 
1237         assertNull("Certificate should not exist in keystore",
1238                 mKeyStore.getCertificate(TEST_ALIAS_2));
1239 
1240         Certificate retrieved = mKeyStore.getCertificate(TEST_ALIAS_1);
1241 
1242         assertNotNull("Retrieved certificate should not be null", retrieved);
1243 
1244         CertificateFactory f = CertificateFactory.getInstance("X.509");
1245         Certificate actual = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1246 
1247         assertEquals("Actual and retrieved certificates should be the same", actual, retrieved);
1248     }
1249 
testKeyStore_GetCertificate_NonExist_Unencrypted_Failure()1250     public void testKeyStore_GetCertificate_NonExist_Unencrypted_Failure() throws Exception {
1251         mKeyStore.load(null, null);
1252 
1253         assertNull("Certificate should not exist in keystore",
1254                 mKeyStore.getCertificate(TEST_ALIAS_1));
1255     }
1256 
testKeyStore_GetCertificateAlias_CAEntry_Unencrypted_Success()1257     public void testKeyStore_GetCertificateAlias_CAEntry_Unencrypted_Success() throws Exception {
1258         mKeyStore.load(null, null);
1259 
1260         Certificate cert = generateCertificate(FAKE_RSA_CA_1);
1261         mKeyStore.setCertificateEntry(TEST_ALIAS_1, cert);
1262 
1263         assertEquals("Stored certificate alias should be found", TEST_ALIAS_1,
1264                 mKeyStore.getCertificateAlias(cert));
1265     }
1266 
testKeyStore_GetCertificateAlias_PrivateKeyEntry_Unencrypted_Success()1267     public void testKeyStore_GetCertificateAlias_PrivateKeyEntry_Unencrypted_Success()
1268             throws Exception {
1269         mKeyStore.load(null, null);
1270 
1271         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1272 
1273         CertificateFactory f = CertificateFactory.getInstance("X.509");
1274         Certificate actual = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1275 
1276         assertEquals("Stored certificate alias should be found", TEST_ALIAS_1,
1277                 mKeyStore.getCertificateAlias(actual));
1278     }
1279 
testKeyStore_GetCertificateAlias_CAEntry_WithPrivateKeyUsingCA_Unencrypted_Success()1280     public void testKeyStore_GetCertificateAlias_CAEntry_WithPrivateKeyUsingCA_Unencrypted_Success()
1281             throws Exception {
1282         mKeyStore.load(null, null);
1283 
1284         Certificate actual = generateCertificate(FAKE_RSA_CA_1);
1285 
1286         // Insert TrustedCertificateEntry with CA name
1287         mKeyStore.setCertificateEntry(TEST_ALIAS_2, actual);
1288 
1289         // Insert PrivateKeyEntry that uses the same CA
1290         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1291 
1292         assertEquals("Stored certificate alias should be found", TEST_ALIAS_2,
1293                 mKeyStore.getCertificateAlias(actual));
1294     }
1295 
testKeyStore_GetCertificateAlias_NonExist_Empty_Unencrypted_Failure()1296     public void testKeyStore_GetCertificateAlias_NonExist_Empty_Unencrypted_Failure()
1297             throws Exception {
1298         mKeyStore.load(null, null);
1299 
1300         CertificateFactory f = CertificateFactory.getInstance("X.509");
1301         Certificate actual = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1302 
1303         assertNull("Stored certificate alias should not be found",
1304                 mKeyStore.getCertificateAlias(actual));
1305     }
1306 
testKeyStore_GetCertificateAlias_NonExist_Unencrypted_Failure()1307     public void testKeyStore_GetCertificateAlias_NonExist_Unencrypted_Failure() throws Exception {
1308         mKeyStore.load(null, null);
1309 
1310         Certificate ca = generateCertificate(FAKE_RSA_CA_1);
1311 
1312         // Insert TrustedCertificateEntry with CA name
1313         mKeyStore.setCertificateEntry(TEST_ALIAS_1, ca);
1314 
1315         Certificate userCert = generateCertificate(FAKE_RSA_USER_1);
1316 
1317         assertNull("Stored certificate alias should be found",
1318                 mKeyStore.getCertificateAlias(userCert));
1319     }
1320 
testKeyStore_GetCertificateChain_SingleLength_Unencrypted_Success()1321     public void testKeyStore_GetCertificateChain_SingleLength_Unencrypted_Success() throws Exception {
1322         mKeyStore.load(null, null);
1323 
1324         // TEST_ALIAS_1
1325         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1326 
1327         Certificate[] expected = new Certificate[2];
1328         expected[0] = generateCertificate(FAKE_RSA_USER_1);
1329         expected[1] = generateCertificate(FAKE_RSA_CA_1);
1330 
1331         Certificate[] actual = mKeyStore.getCertificateChain(TEST_ALIAS_1);
1332 
1333         assertNotNull("Returned certificate chain should not be null", actual);
1334         assertEquals("Returned certificate chain should be correct size", expected.length,
1335                 actual.length);
1336         assertEquals("First certificate should be user certificate", expected[0], actual[0]);
1337         assertEquals("Second certificate should be CA certificate", expected[1], actual[1]);
1338 
1339         // Negative test when keystore is populated.
1340         assertNull("Stored certificate alias should not be found",
1341                 mKeyStore.getCertificateChain(TEST_ALIAS_2));
1342     }
1343 
testKeyStore_GetCertificateChain_NonExist_Unencrypted_Failure()1344     public void testKeyStore_GetCertificateChain_NonExist_Unencrypted_Failure() throws Exception {
1345         mKeyStore.load(null, null);
1346 
1347         assertNull("Stored certificate alias should not be found",
1348                 mKeyStore.getCertificateChain(TEST_ALIAS_1));
1349     }
1350 
testKeyStore_GetCreationDate_PrivateKeyEntry_Unencrypted_Success()1351     public void testKeyStore_GetCreationDate_PrivateKeyEntry_Unencrypted_Success() throws Exception {
1352         mKeyStore.load(null, null);
1353 
1354         // TEST_ALIAS_1
1355         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1356 
1357         Date now = new Date();
1358         Date actual = mKeyStore.getCreationDate(TEST_ALIAS_1);
1359 
1360         Date expectedAfter = new Date(now.getTime() - SLOP_TIME_MILLIS);
1361         Date expectedBefore = new Date(now.getTime() + SLOP_TIME_MILLIS);
1362 
1363         assertTrue("Time should be close to current time", actual.before(expectedBefore));
1364         assertTrue("Time should be close to current time", actual.after(expectedAfter));
1365     }
1366 
testKeyStore_GetCreationDate_CAEntry_Unencrypted_Success()1367     public void testKeyStore_GetCreationDate_CAEntry_Unencrypted_Success() throws Exception {
1368         mKeyStore.load(null, null);
1369 
1370         // Insert TrustedCertificateEntry with CA name
1371         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
1372 
1373         Date now = new Date();
1374         Date actual = mKeyStore.getCreationDate(TEST_ALIAS_1);
1375         assertNotNull("Certificate should be found", actual);
1376 
1377         Date expectedAfter = new Date(now.getTime() - SLOP_TIME_MILLIS);
1378         Date expectedBefore = new Date(now.getTime() + SLOP_TIME_MILLIS);
1379 
1380         assertTrue("Time should be close to current time", actual.before(expectedBefore));
1381         assertTrue("Time should be close to current time", actual.after(expectedAfter));
1382     }
1383 
testKeyStore_GetEntry_NullParams_Unencrypted_Success()1384     public void testKeyStore_GetEntry_NullParams_Unencrypted_Success() throws Exception {
1385         mKeyStore.load(null, null);
1386 
1387         // TEST_ALIAS_1
1388         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1389 
1390         Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1391         assertNotNull("Entry should exist", entry);
1392 
1393         assertTrue("Should be a PrivateKeyEntry", entry instanceof PrivateKeyEntry);
1394 
1395         PrivateKeyEntry keyEntry = (PrivateKeyEntry) entry;
1396 
1397         assertPrivateKeyEntryEquals(keyEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1, FAKE_RSA_CA_1);
1398     }
1399 
testKeyStore_GetEntry_DSA_NullParams_Unencrypted_Success()1400     public void testKeyStore_GetEntry_DSA_NullParams_Unencrypted_Success() throws Exception {
1401         mKeyStore.load(null, null);
1402 
1403         // TEST_ALIAS_1
1404         mKeyStore.setEntry(TEST_ALIAS_1, makeUserDsaKey1(), null);
1405 
1406         Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1407         assertNotNull("Entry should exist", entry);
1408 
1409         assertTrue("Should be a PrivateKeyEntry", entry instanceof PrivateKeyEntry);
1410 
1411         PrivateKeyEntry keyEntry = (PrivateKeyEntry) entry;
1412 
1413         assertPrivateKeyEntryEquals(keyEntry, "DSA", FAKE_DSA_KEY_1, FAKE_DSA_USER_1, FAKE_DSA_CA_1);
1414     }
1415 
testKeyStore_GetEntry_EC_NullParams_Unencrypted_Success()1416     public void testKeyStore_GetEntry_EC_NullParams_Unencrypted_Success() throws Exception {
1417         mKeyStore.load(null, null);
1418 
1419         // TEST_ALIAS_1
1420         mKeyStore.setEntry(TEST_ALIAS_1, makeUserEcKey1(), null);
1421 
1422         Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1423         assertNotNull("Entry should exist", entry);
1424 
1425         assertTrue("Should be a PrivateKeyEntry", entry instanceof PrivateKeyEntry);
1426 
1427         PrivateKeyEntry keyEntry = (PrivateKeyEntry) entry;
1428 
1429         assertPrivateKeyEntryEquals(keyEntry, "EC", FAKE_EC_KEY_1, FAKE_EC_USER_1, FAKE_EC_CA_1);
1430     }
1431 
testKeyStore_GetEntry_RSA_NullParams_Unencrypted_Success()1432     public void testKeyStore_GetEntry_RSA_NullParams_Unencrypted_Success() throws Exception {
1433         mKeyStore.load(null, null);
1434 
1435         // TEST_ALIAS_1
1436         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1437 
1438         Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1439         assertNotNull("Entry should exist", entry);
1440 
1441         assertTrue("Should be a PrivateKeyEntry", entry instanceof PrivateKeyEntry);
1442 
1443         PrivateKeyEntry keyEntry = (PrivateKeyEntry) entry;
1444 
1445         assertPrivateKeyEntryEquals(keyEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1446                 FAKE_RSA_CA_1);
1447     }
1448 
1449     @SuppressWarnings("unchecked")
assertPrivateKeyEntryEquals(PrivateKeyEntry keyEntry, String keyType, byte[] key, byte[] cert, byte[] ca)1450     private void assertPrivateKeyEntryEquals(PrivateKeyEntry keyEntry, String keyType, byte[] key,
1451             byte[] cert, byte[] ca) throws Exception {
1452         KeyFactory keyFact = KeyFactory.getInstance(keyType);
1453         PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(key));
1454 
1455         CertificateFactory certFact = CertificateFactory.getInstance("X.509");
1456         Certificate expectedCert = certFact.generateCertificate(new ByteArrayInputStream(cert));
1457 
1458         final Collection<Certificate> expectedChain;
1459         if (ca != null) {
1460             expectedChain = (Collection<Certificate>) certFact
1461                     .generateCertificates(new ByteArrayInputStream(ca));
1462         } else {
1463             expectedChain = null;
1464         }
1465 
1466         assertPrivateKeyEntryEquals(keyEntry, expectedKey, expectedCert, expectedChain);
1467     }
1468 
assertPrivateKeyEntryEquals(PrivateKeyEntry keyEntry, PrivateKey expectedKey, Certificate expectedCert, Collection<Certificate> expectedChain)1469     private void assertPrivateKeyEntryEquals(PrivateKeyEntry keyEntry, PrivateKey expectedKey,
1470             Certificate expectedCert, Collection<Certificate> expectedChain) throws Exception {
1471         final PrivateKey privKey = keyEntry.getPrivateKey();
1472         final PublicKey pubKey = keyEntry.getCertificate().getPublicKey();
1473 
1474         if (expectedKey instanceof DSAPrivateKey) {
1475             assertEquals("Returned PrivateKey should be what we inserted",
1476                     ((DSAPrivateKey) expectedKey).getParams(),
1477                     ((DSAPublicKey) pubKey).getParams());
1478         } else if (expectedKey instanceof ECPrivateKey) {
1479             assertEquals("Returned PrivateKey should be what we inserted",
1480                     ((ECPrivateKey) expectedKey).getParams().getCurve(),
1481                     ((ECPublicKey) pubKey).getParams().getCurve());
1482         } else if (expectedKey instanceof RSAPrivateKey) {
1483             assertEquals("Returned PrivateKey should be what we inserted",
1484                     ((RSAPrivateKey) expectedKey).getModulus(),
1485                     ((RSAPrivateKey) privKey).getModulus());
1486         }
1487 
1488         assertNull("getFormat() should return null", privKey.getFormat());
1489         assertNull("getEncoded() should return null", privKey.getEncoded());
1490 
1491         assertEquals("Public keys should be in X.509 format", "X.509", pubKey.getFormat());
1492         assertNotNull("Public keys should be encodable", pubKey.getEncoded());
1493 
1494         assertEquals("Returned Certificate should be what we inserted", expectedCert,
1495                 keyEntry.getCertificate());
1496 
1497         Certificate[] actualChain = keyEntry.getCertificateChain();
1498 
1499         assertEquals("First certificate in chain should be user cert", expectedCert, actualChain[0]);
1500 
1501         if (expectedChain == null) {
1502             assertEquals("Certificate chain should not include CAs", 1, actualChain.length);
1503         } else {
1504             assertEquals("Chains should be the same size", expectedChain.size() + 1,
1505                     actualChain.length);
1506             int i = 1;
1507             final Iterator<Certificate> it = expectedChain.iterator();
1508             while (it.hasNext() && i < actualChain.length) {
1509                 assertEquals("CA chain certificate should equal what we put in", it.next(),
1510                         actualChain[i++]);
1511             }
1512         }
1513     }
1514 
testKeyStore_GetEntry_Nonexistent_NullParams_Unencrypted_Failure()1515     public void testKeyStore_GetEntry_Nonexistent_NullParams_Unencrypted_Failure() throws Exception {
1516         mKeyStore.load(null, null);
1517 
1518         assertNull("A non-existent entry should return null",
1519                 mKeyStore.getEntry(TEST_ALIAS_1, null));
1520     }
1521 
testKeyStore_GetKey_NoPassword_Unencrypted_Success()1522     public void testKeyStore_GetKey_NoPassword_Unencrypted_Success() throws Exception {
1523         mKeyStore.load(null, null);
1524 
1525         // TEST_ALIAS_1
1526         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1527 
1528         Key key = mKeyStore.getKey(TEST_ALIAS_1, null);
1529         assertNotNull("Key should exist", key);
1530 
1531         assertTrue("Should be a RSAPrivateKey", key instanceof RSAPrivateKey);
1532 
1533         RSAPrivateKey actualKey = (RSAPrivateKey) key;
1534 
1535         KeyFactory keyFact = KeyFactory.getInstance("RSA");
1536         PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1537 
1538         assertEquals("Inserted key should be same as retrieved key",
1539                 ((RSAPrivateKey) expectedKey).getModulus(), actualKey.getModulus());
1540     }
1541 
testKeyStore_GetKey_Certificate_Unencrypted_Failure()1542     public void testKeyStore_GetKey_Certificate_Unencrypted_Failure() throws Exception {
1543         mKeyStore.load(null, null);
1544 
1545         // Insert TrustedCertificateEntry with CA name
1546         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
1547 
1548         assertNull("Certificate entries should return null", mKeyStore.getKey(TEST_ALIAS_1, null));
1549     }
1550 
testKeyStore_GetKey_NonExistent_Unencrypted_Failure()1551     public void testKeyStore_GetKey_NonExistent_Unencrypted_Failure() throws Exception {
1552         mKeyStore.load(null, null);
1553 
1554         assertNull("A non-existent entry should return null", mKeyStore.getKey(TEST_ALIAS_1, null));
1555     }
1556 
testKeyStore_GetProvider_Unencrypted_Success()1557     public void testKeyStore_GetProvider_Unencrypted_Success() throws Exception {
1558         assertEquals("AndroidKeyStore", mKeyStore.getProvider().getName());
1559     }
1560 
testKeyStore_GetType_Unencrypted_Success()1561     public void testKeyStore_GetType_Unencrypted_Success() throws Exception {
1562         assertEquals("AndroidKeyStore", mKeyStore.getType());
1563     }
1564 
testKeyStore_IsCertificateEntry_CA_Unencrypted_Success()1565     public void testKeyStore_IsCertificateEntry_CA_Unencrypted_Success() throws Exception {
1566         mKeyStore.load(null, null);
1567 
1568         // Insert TrustedCertificateEntry with CA name
1569         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
1570 
1571         assertTrue("Should return true for CA certificate",
1572                 mKeyStore.isCertificateEntry(TEST_ALIAS_1));
1573     }
1574 
testKeyStore_IsCertificateEntry_PrivateKey_Unencrypted_Failure()1575     public void testKeyStore_IsCertificateEntry_PrivateKey_Unencrypted_Failure() throws Exception {
1576         mKeyStore.load(null, null);
1577 
1578         // TEST_ALIAS_1
1579         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1580 
1581         assertFalse("Should return false for PrivateKeyEntry",
1582                 mKeyStore.isCertificateEntry(TEST_ALIAS_1));
1583     }
1584 
testKeyStore_IsCertificateEntry_NonExist_Unencrypted_Failure()1585     public void testKeyStore_IsCertificateEntry_NonExist_Unencrypted_Failure() throws Exception {
1586         mKeyStore.load(null, null);
1587 
1588         assertFalse("Should return false for non-existent entry",
1589                 mKeyStore.isCertificateEntry(TEST_ALIAS_1));
1590     }
1591 
testKeyStore_IsKeyEntry_PrivateKey_Unencrypted_Success()1592     public void testKeyStore_IsKeyEntry_PrivateKey_Unencrypted_Success() throws Exception {
1593         mKeyStore.load(null, null);
1594 
1595         // TEST_ALIAS_1
1596         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1597 
1598         assertTrue("Should return true for PrivateKeyEntry", mKeyStore.isKeyEntry(TEST_ALIAS_1));
1599     }
1600 
testKeyStore_IsKeyEntry_CA_Unencrypted_Failure()1601     public void testKeyStore_IsKeyEntry_CA_Unencrypted_Failure() throws Exception {
1602         mKeyStore.load(null, null);
1603 
1604         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
1605 
1606         assertFalse("Should return false for CA certificate", mKeyStore.isKeyEntry(TEST_ALIAS_1));
1607     }
1608 
testKeyStore_IsKeyEntry_NonExist_Unencrypted_Failure()1609     public void testKeyStore_IsKeyEntry_NonExist_Unencrypted_Failure() throws Exception {
1610         mKeyStore.load(null, null);
1611 
1612         assertFalse("Should return false for non-existent entry",
1613                 mKeyStore.isKeyEntry(TEST_ALIAS_1));
1614     }
1615 
testKeyStore_SetCertificate_CA_Unencrypted_Success()1616     public void testKeyStore_SetCertificate_CA_Unencrypted_Success() throws Exception {
1617         final Certificate actual = generateCertificate(FAKE_RSA_CA_1);
1618 
1619         mKeyStore.load(null, null);
1620 
1621         mKeyStore.setCertificateEntry(TEST_ALIAS_1, actual);
1622         assertAliases(new String[] { TEST_ALIAS_1 });
1623 
1624         Certificate retrieved = mKeyStore.getCertificate(TEST_ALIAS_1);
1625 
1626         assertEquals("Retrieved certificate should be the same as the one inserted", actual,
1627                 retrieved);
1628     }
1629 
testKeyStore_SetCertificate_CAExists_Overwrite_Unencrypted_Success()1630     public void testKeyStore_SetCertificate_CAExists_Overwrite_Unencrypted_Success()
1631             throws Exception {
1632         mKeyStore.load(null, null);
1633 
1634         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
1635 
1636         assertAliases(new String[] { TEST_ALIAS_1 });
1637 
1638         final Certificate cert = generateCertificate(FAKE_RSA_CA_1);
1639 
1640         // TODO have separate FAKE_CA for second test
1641         mKeyStore.setCertificateEntry(TEST_ALIAS_1, cert);
1642 
1643         assertAliases(new String[] { TEST_ALIAS_1 });
1644     }
1645 
testKeyStore_SetCertificate_PrivateKeyExists_Unencrypted_Failure()1646     public void testKeyStore_SetCertificate_PrivateKeyExists_Unencrypted_Failure() throws Exception {
1647         mKeyStore.load(null, null);
1648 
1649         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
1650 
1651         assertAliases(new String[] { TEST_ALIAS_1 });
1652 
1653         final Certificate cert = generateCertificate(FAKE_RSA_CA_1);
1654 
1655         try {
1656             mKeyStore.setCertificateEntry(TEST_ALIAS_1, cert);
1657             fail("Should throw when trying to overwrite a PrivateKey entry with a Certificate");
1658         } catch (KeyStoreException success) {
1659         }
1660     }
1661 
testKeyStore_SetEntry_PrivateKeyEntry_Unencrypted_Success()1662     public void testKeyStore_SetEntry_PrivateKeyEntry_Unencrypted_Success() throws Exception {
1663         mKeyStore.load(null, null);
1664 
1665         KeyFactory keyFact = KeyFactory.getInstance("RSA");
1666         PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1667 
1668         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1669 
1670         final Certificate[] expectedChain = new Certificate[2];
1671         expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1672         expectedChain[1] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1673 
1674         PrivateKeyEntry expected = new PrivateKeyEntry(expectedKey, expectedChain);
1675 
1676         mKeyStore.setEntry(TEST_ALIAS_1, expected, null);
1677 
1678         Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1679         assertNotNull("Retrieved entry should exist", actualEntry);
1680 
1681         assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1682                 actualEntry instanceof PrivateKeyEntry);
1683 
1684         PrivateKeyEntry actual = (PrivateKeyEntry) actualEntry;
1685 
1686         assertPrivateKeyEntryEquals(actual, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1, FAKE_RSA_CA_1);
1687     }
1688 
testKeyStore_SetEntry_PrivateKeyEntry_Params_Unencrypted_Failure()1689     public void testKeyStore_SetEntry_PrivateKeyEntry_Params_Unencrypted_Failure() throws Exception {
1690         mKeyStore.load(null, null);
1691 
1692         KeyFactory keyFact = KeyFactory.getInstance("RSA");
1693         PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1694 
1695         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1696 
1697         final Certificate[] expectedChain = new Certificate[2];
1698         expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1699         expectedChain[1] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1700 
1701         PrivateKeyEntry entry = new PrivateKeyEntry(expectedKey, expectedChain);
1702 
1703         try {
1704             mKeyStore.setEntry(TEST_ALIAS_1, entry,
1705                     new KeyStoreParameter.Builder(getContext())
1706                     .setEncryptionRequired(true)
1707                     .build());
1708             fail("Shouldn't be able to insert encrypted entry when KeyStore uninitialized");
1709         } catch (KeyStoreException expected) {
1710         }
1711 
1712         assertNull(mKeyStore.getEntry(TEST_ALIAS_1, null));
1713     }
1714 
testKeyStore_SetEntry_PrivateKeyEntry_Overwrites_PrivateKeyEntry_Unencrypted_Success()1715     public void testKeyStore_SetEntry_PrivateKeyEntry_Overwrites_PrivateKeyEntry_Unencrypted_Success()
1716             throws Exception {
1717         mKeyStore.load(null, null);
1718 
1719         final KeyFactory keyFact = KeyFactory.getInstance("RSA");
1720         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1721 
1722         // Start with PrivateKeyEntry
1723         {
1724             PrivateKey expectedKey = keyFact
1725                     .generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1726 
1727             final Certificate[] expectedChain = new Certificate[2];
1728             expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1729             expectedChain[1] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1730 
1731             PrivateKeyEntry expected = new PrivateKeyEntry(expectedKey, expectedChain);
1732 
1733             mKeyStore.setEntry(TEST_ALIAS_1, expected, null);
1734 
1735             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1736             assertNotNull("Retrieved entry should exist", actualEntry);
1737 
1738             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1739                     actualEntry instanceof PrivateKeyEntry);
1740 
1741             PrivateKeyEntry actual = (PrivateKeyEntry) actualEntry;
1742 
1743             assertPrivateKeyEntryEquals(actual, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1744                     FAKE_RSA_CA_1);
1745         }
1746 
1747         // TODO make entirely new test vector for the overwrite
1748         // Replace with PrivateKeyEntry
1749         {
1750             PrivateKey expectedKey = keyFact
1751                     .generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1752 
1753             final Certificate[] expectedChain = new Certificate[2];
1754             expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1755             expectedChain[1] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1756 
1757             PrivateKeyEntry expected = new PrivateKeyEntry(expectedKey, expectedChain);
1758 
1759             mKeyStore.setEntry(TEST_ALIAS_1, expected, null);
1760 
1761             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1762             assertNotNull("Retrieved entry should exist", actualEntry);
1763 
1764             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1765                     actualEntry instanceof PrivateKeyEntry);
1766 
1767             PrivateKeyEntry actual = (PrivateKeyEntry) actualEntry;
1768 
1769             assertPrivateKeyEntryEquals(actual, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1770                     FAKE_RSA_CA_1);
1771         }
1772     }
1773 
testKeyStore_SetEntry_CAEntry_Overwrites_PrivateKeyEntry_Unencrypted_Success()1774     public void testKeyStore_SetEntry_CAEntry_Overwrites_PrivateKeyEntry_Unencrypted_Success()
1775             throws Exception {
1776         mKeyStore.load(null, null);
1777 
1778         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1779 
1780         // Start with TrustedCertificateEntry
1781         {
1782             final Certificate caCert = f
1783                     .generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1784 
1785             TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
1786             mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
1787 
1788             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1789             assertNotNull("Retrieved entry should exist", actualEntry);
1790             assertTrue("Retrieved entry should be of type TrustedCertificateEntry",
1791                     actualEntry instanceof TrustedCertificateEntry);
1792             TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
1793             assertEquals("Stored and retrieved certificates should be the same",
1794                     expectedCertEntry.getTrustedCertificate(),
1795                     actualCertEntry.getTrustedCertificate());
1796         }
1797 
1798         // Replace with PrivateKeyEntry
1799         {
1800             KeyFactory keyFact = KeyFactory.getInstance("RSA");
1801             PrivateKey expectedKey = keyFact
1802                     .generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1803             final Certificate[] expectedChain = new Certificate[2];
1804             expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1805             expectedChain[1] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1806 
1807             PrivateKeyEntry expectedPrivEntry = new PrivateKeyEntry(expectedKey, expectedChain);
1808 
1809             mKeyStore.setEntry(TEST_ALIAS_1, expectedPrivEntry, null);
1810 
1811             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1812             assertNotNull("Retrieved entry should exist", actualEntry);
1813             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1814                     actualEntry instanceof PrivateKeyEntry);
1815 
1816             PrivateKeyEntry actualPrivEntry = (PrivateKeyEntry) actualEntry;
1817             assertPrivateKeyEntryEquals(actualPrivEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1818                     FAKE_RSA_CA_1);
1819         }
1820     }
1821 
testKeyStore_SetEntry_PrivateKeyEntry_Overwrites_CAEntry_Unencrypted_Success()1822     public void testKeyStore_SetEntry_PrivateKeyEntry_Overwrites_CAEntry_Unencrypted_Success()
1823             throws Exception {
1824         mKeyStore.load(null, null);
1825 
1826         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1827 
1828         final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1829 
1830         // Start with PrivateKeyEntry
1831         {
1832             KeyFactory keyFact = KeyFactory.getInstance("RSA");
1833             PrivateKey expectedKey = keyFact
1834                     .generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1835             final Certificate[] expectedChain = new Certificate[2];
1836             expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1837             expectedChain[1] = caCert;
1838 
1839             PrivateKeyEntry expectedPrivEntry = new PrivateKeyEntry(expectedKey, expectedChain);
1840 
1841             mKeyStore.setEntry(TEST_ALIAS_1, expectedPrivEntry, null);
1842 
1843             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1844             assertNotNull("Retrieved entry should exist", actualEntry);
1845             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1846                     actualEntry instanceof PrivateKeyEntry);
1847 
1848             PrivateKeyEntry actualPrivEntry = (PrivateKeyEntry) actualEntry;
1849             assertPrivateKeyEntryEquals(actualPrivEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1850                     FAKE_RSA_CA_1);
1851         }
1852 
1853         // Replace with TrustedCertificateEntry
1854         {
1855             TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
1856             mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
1857 
1858             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1859             assertNotNull("Retrieved entry should exist", actualEntry);
1860             assertTrue("Retrieved entry should be of type TrustedCertificateEntry",
1861                     actualEntry instanceof TrustedCertificateEntry);
1862             TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
1863             assertEquals("Stored and retrieved certificates should be the same",
1864                     expectedCertEntry.getTrustedCertificate(),
1865                     actualCertEntry.getTrustedCertificate());
1866         }
1867     }
1868 
testKeyStore_SetEntry_PrivateKeyEntry_Overwrites_ShortPrivateKeyEntry_Unencrypted_Success()1869     public void testKeyStore_SetEntry_PrivateKeyEntry_Overwrites_ShortPrivateKeyEntry_Unencrypted_Success()
1870             throws Exception {
1871         mKeyStore.load(null, null);
1872 
1873         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1874 
1875         final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1876 
1877         // Start with PrivateKeyEntry
1878         {
1879             KeyFactory keyFact = KeyFactory.getInstance("RSA");
1880             PrivateKey expectedKey = keyFact
1881                     .generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1882             final Certificate[] expectedChain = new Certificate[2];
1883             expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1884             expectedChain[1] = caCert;
1885 
1886             PrivateKeyEntry expectedPrivEntry = new PrivateKeyEntry(expectedKey, expectedChain);
1887 
1888             mKeyStore.setEntry(TEST_ALIAS_1, expectedPrivEntry, null);
1889 
1890             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1891             assertNotNull("Retrieved entry should exist", actualEntry);
1892             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1893                     actualEntry instanceof PrivateKeyEntry);
1894 
1895             PrivateKeyEntry actualPrivEntry = (PrivateKeyEntry) actualEntry;
1896             assertPrivateKeyEntryEquals(actualPrivEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1897                     FAKE_RSA_CA_1);
1898         }
1899 
1900         // Replace with PrivateKeyEntry that has no chain
1901         {
1902             KeyFactory keyFact = KeyFactory.getInstance("RSA");
1903             PrivateKey expectedKey = keyFact
1904                     .generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1905             final Certificate[] expectedChain = new Certificate[1];
1906             expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1907 
1908             PrivateKeyEntry expectedPrivEntry = new PrivateKeyEntry(expectedKey, expectedChain);
1909 
1910             mKeyStore.setEntry(TEST_ALIAS_1, expectedPrivEntry, null);
1911 
1912             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1913             assertNotNull("Retrieved entry should exist", actualEntry);
1914             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
1915                     actualEntry instanceof PrivateKeyEntry);
1916 
1917             PrivateKeyEntry actualPrivEntry = (PrivateKeyEntry) actualEntry;
1918             assertPrivateKeyEntryEquals(actualPrivEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
1919                     null);
1920         }
1921     }
1922 
testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Unencrypted_Success()1923     public void testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Unencrypted_Success()
1924             throws Exception {
1925         mKeyStore.load(null, null);
1926 
1927         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1928 
1929         // Insert TrustedCertificateEntry
1930         {
1931             final Certificate caCert = f
1932                     .generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1933 
1934             TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
1935             mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
1936 
1937             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1938             assertNotNull("Retrieved entry should exist", actualEntry);
1939             assertTrue("Retrieved entry should be of type TrustedCertificateEntry",
1940                     actualEntry instanceof TrustedCertificateEntry);
1941             TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
1942             assertEquals("Stored and retrieved certificates should be the same",
1943                     expectedCertEntry.getTrustedCertificate(),
1944                     actualCertEntry.getTrustedCertificate());
1945         }
1946 
1947         // Replace with TrustedCertificateEntry of USER
1948         {
1949             final Certificate userCert = f.generateCertificate(new ByteArrayInputStream(
1950                     FAKE_RSA_USER_1));
1951 
1952             TrustedCertificateEntry expectedUserEntry = new TrustedCertificateEntry(userCert);
1953             mKeyStore.setEntry(TEST_ALIAS_1, expectedUserEntry, null);
1954 
1955             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
1956             assertNotNull("Retrieved entry should exist", actualEntry);
1957             assertTrue("Retrieved entry should be of type TrustedCertificateEntry",
1958                     actualEntry instanceof TrustedCertificateEntry);
1959             TrustedCertificateEntry actualUserEntry = (TrustedCertificateEntry) actualEntry;
1960             assertEquals("Stored and retrieved certificates should be the same",
1961                     expectedUserEntry.getTrustedCertificate(),
1962                     actualUserEntry.getTrustedCertificate());
1963         }
1964     }
1965 
testKeyStore_SetKeyEntry_ProtectedKey_Unencrypted_Failure()1966     public void testKeyStore_SetKeyEntry_ProtectedKey_Unencrypted_Failure() throws Exception {
1967         mKeyStore.load(null, null);
1968 
1969         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1970 
1971         final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1972 
1973         KeyFactory keyFact = KeyFactory.getInstance("RSA");
1974         PrivateKey privKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1975         final Certificate[] chain = new Certificate[2];
1976         chain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1977         chain[1] = caCert;
1978 
1979         try {
1980             mKeyStore.setKeyEntry(TEST_ALIAS_1, privKey, "foo".toCharArray(), chain);
1981             fail("Should fail when a password is specified");
1982         } catch (KeyStoreException success) {
1983         }
1984     }
1985 
testKeyStore_SetKeyEntry_Unencrypted_Success()1986     public void testKeyStore_SetKeyEntry_Unencrypted_Success() throws Exception {
1987         mKeyStore.load(null, null);
1988 
1989         final CertificateFactory f = CertificateFactory.getInstance("X.509");
1990 
1991         final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
1992 
1993         KeyFactory keyFact = KeyFactory.getInstance("RSA");
1994         PrivateKey privKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
1995         final Certificate[] chain = new Certificate[2];
1996         chain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
1997         chain[1] = caCert;
1998 
1999         mKeyStore.setKeyEntry(TEST_ALIAS_1, privKey, null, chain);
2000 
2001         Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
2002         assertNotNull("Retrieved entry should exist", actualEntry);
2003 
2004         assertTrue("Retrieved entry should be of type PrivateKeyEntry",
2005                 actualEntry instanceof PrivateKeyEntry);
2006 
2007         PrivateKeyEntry actual = (PrivateKeyEntry) actualEntry;
2008 
2009         assertPrivateKeyEntryEquals(actual, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1, FAKE_RSA_CA_1);
2010     }
2011 
testKeyStore_SetKeyEntry_Replaced_Unencrypted_Success()2012     public void testKeyStore_SetKeyEntry_Replaced_Unencrypted_Success() throws Exception {
2013         mKeyStore.load(null, null);
2014 
2015         final CertificateFactory f = CertificateFactory.getInstance("X.509");
2016 
2017         final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
2018 
2019         // Insert initial key
2020         {
2021             KeyFactory keyFact = KeyFactory.getInstance("RSA");
2022             PrivateKey privKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
2023             final Certificate[] chain = new Certificate[2];
2024             chain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
2025             chain[1] = caCert;
2026 
2027             mKeyStore.setKeyEntry(TEST_ALIAS_1, privKey, null, chain);
2028 
2029             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
2030             assertNotNull("Retrieved entry should exist", actualEntry);
2031 
2032             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
2033                     actualEntry instanceof PrivateKeyEntry);
2034 
2035             PrivateKeyEntry actual = (PrivateKeyEntry) actualEntry;
2036 
2037             assertPrivateKeyEntryEquals(actual, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
2038                     FAKE_RSA_CA_1);
2039         }
2040 
2041         // TODO make a separate key
2042         // Replace key
2043         {
2044             KeyFactory keyFact = KeyFactory.getInstance("RSA");
2045             PrivateKey privKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
2046             final Certificate[] chain = new Certificate[2];
2047             chain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
2048             chain[1] = caCert;
2049 
2050             mKeyStore.setKeyEntry(TEST_ALIAS_1, privKey, null, chain);
2051 
2052             Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
2053             assertNotNull("Retrieved entry should exist", actualEntry);
2054 
2055             assertTrue("Retrieved entry should be of type PrivateKeyEntry",
2056                     actualEntry instanceof PrivateKeyEntry);
2057 
2058             PrivateKeyEntry actual = (PrivateKeyEntry) actualEntry;
2059 
2060             assertPrivateKeyEntryEquals(actual, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1,
2061                     FAKE_RSA_CA_1);
2062         }
2063     }
2064 
testKeyStore_SetKeyEntry_ReplacedChain_Unencrypted_Success()2065     public void testKeyStore_SetKeyEntry_ReplacedChain_Unencrypted_Success() throws Exception {
2066         mKeyStore.load(null, null);
2067 
2068         // Create key #1
2069         {
2070             KeyStore.PrivateKeyEntry privEntry = makeUserRsaKey1();
2071             mKeyStore.setEntry(TEST_ALIAS_1, privEntry, null);
2072 
2073             Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
2074 
2075             assertTrue(entry instanceof PrivateKeyEntry);
2076 
2077             PrivateKeyEntry keyEntry = (PrivateKeyEntry) entry;
2078 
2079             ArrayList<Certificate> chain = new ArrayList<Certificate>();
2080             chain.add(generateCertificate(FAKE_RSA_CA_1));
2081             assertPrivateKeyEntryEquals(keyEntry, privEntry.getPrivateKey(),
2082                     privEntry.getCertificate(), chain);
2083         }
2084 
2085         // Replace key #1 with new chain
2086         {
2087             Key key = mKeyStore.getKey(TEST_ALIAS_1, null);
2088 
2089             assertTrue(key instanceof PrivateKey);
2090 
2091             PrivateKey expectedKey = (PrivateKey) key;
2092 
2093             Certificate expectedCert = generateCertificate(FAKE_RSA_USER_1);
2094 
2095             mKeyStore.setKeyEntry(TEST_ALIAS_1, expectedKey, null,
2096                     new Certificate[] { expectedCert });
2097 
2098             Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
2099 
2100             assertTrue(entry instanceof PrivateKeyEntry);
2101 
2102             PrivateKeyEntry keyEntry = (PrivateKeyEntry) entry;
2103 
2104             assertPrivateKeyEntryEquals(keyEntry, expectedKey, expectedCert, null);
2105         }
2106     }
2107 
testKeyStore_SetKeyEntry_ReplacedChain_DifferentPrivateKey_Unencrypted_Failure()2108     public void testKeyStore_SetKeyEntry_ReplacedChain_DifferentPrivateKey_Unencrypted_Failure()
2109             throws Exception {
2110         mKeyStore.load(null, null);
2111 
2112         // Create key #1
2113         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
2114 
2115         // Create key #2
2116         mKeyStore.setEntry(TEST_ALIAS_2, makeUserRsaKey1(), null);
2117 
2118 
2119         // Replace key #1 with key #2
2120         {
2121             Key key1 = mKeyStore.getKey(TEST_ALIAS_2, null);
2122 
2123             Certificate cert = generateCertificate(FAKE_RSA_USER_1);
2124 
2125             try {
2126                 mKeyStore.setKeyEntry(TEST_ALIAS_1, key1, null, new Certificate[] { cert });
2127                 fail("Should not allow setting of KeyEntry with wrong PrivaetKey");
2128             } catch (KeyStoreException success) {
2129             }
2130         }
2131     }
2132 
testKeyStore_SetKeyEntry_ReplacedWithSame_UnencryptedToUnencrypted_Failure()2133     public void testKeyStore_SetKeyEntry_ReplacedWithSame_UnencryptedToUnencrypted_Failure()
2134             throws Exception {
2135         mKeyStore.load(null, null);
2136 
2137         // Create key #1
2138         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
2139 
2140         // Replace with same
2141         Entry entry = mKeyStore.getEntry(TEST_ALIAS_1, null);
2142         mKeyStore.setEntry(TEST_ALIAS_1, entry, null);
2143     }
2144 
testKeyStore_Size_Unencrypted_Success()2145     public void testKeyStore_Size_Unencrypted_Success() throws Exception {
2146         mKeyStore.load(null, null);
2147 
2148         mKeyStore.setCertificateEntry(TEST_ALIAS_1, generateCertificate(FAKE_RSA_CA_1));
2149 
2150         assertEquals("The keystore size should match expected", 1, mKeyStore.size());
2151         assertAliases(new String[] { TEST_ALIAS_1 });
2152 
2153         mKeyStore.setCertificateEntry(TEST_ALIAS_2, generateCertificate(FAKE_RSA_CA_1));
2154 
2155         assertEquals("The keystore size should match expected", 2, mKeyStore.size());
2156         assertAliases(new String[] { TEST_ALIAS_1, TEST_ALIAS_2 });
2157 
2158         mKeyStore.setEntry(TEST_ALIAS_3, makeUserRsaKey1(), null);
2159 
2160         assertEquals("The keystore size should match expected", 3, mKeyStore.size());
2161         assertAliases(new String[] { TEST_ALIAS_1, TEST_ALIAS_2, TEST_ALIAS_3 });
2162 
2163         mKeyStore.deleteEntry(TEST_ALIAS_1);
2164 
2165         assertEquals("The keystore size should match expected", 2, mKeyStore.size());
2166         assertAliases(new String[] { TEST_ALIAS_2, TEST_ALIAS_3 });
2167 
2168         mKeyStore.deleteEntry(TEST_ALIAS_3);
2169 
2170         assertEquals("The keystore size should match expected", 1, mKeyStore.size());
2171         assertAliases(new String[] { TEST_ALIAS_2 });
2172     }
2173 
testKeyStore_Store_LoadStoreParam_Unencrypted_Failure()2174     public void testKeyStore_Store_LoadStoreParam_Unencrypted_Failure() throws Exception {
2175         mKeyStore.load(null, null);
2176 
2177         try {
2178             mKeyStore.store(null);
2179             fail("Should throw UnsupportedOperationException when trying to store");
2180         } catch (UnsupportedOperationException success) {
2181         }
2182     }
2183 
testKeyStore_Load_InputStreamSupplied_Unencrypted_Failure()2184     public void testKeyStore_Load_InputStreamSupplied_Unencrypted_Failure() throws Exception {
2185         byte[] buf = "FAKE KEYSTORE".getBytes();
2186         ByteArrayInputStream is = new ByteArrayInputStream(buf);
2187 
2188         try {
2189             mKeyStore.load(is, null);
2190             fail("Should throw IllegalArgumentException when InputStream is supplied");
2191         } catch (IllegalArgumentException success) {
2192         }
2193     }
2194 
testKeyStore_Load_PasswordSupplied_Unencrypted_Failure()2195     public void testKeyStore_Load_PasswordSupplied_Unencrypted_Failure() throws Exception {
2196         try {
2197             mKeyStore.load(null, "password".toCharArray());
2198             fail("Should throw IllegalArgumentException when password is supplied");
2199         } catch (IllegalArgumentException success) {
2200         }
2201     }
2202 
testKeyStore_Store_OutputStream_Unencrypted_Failure()2203     public void testKeyStore_Store_OutputStream_Unencrypted_Failure() throws Exception {
2204         mKeyStore.load(null, null);
2205 
2206         OutputStream sink = new ByteArrayOutputStream();
2207         try {
2208             mKeyStore.store(sink, null);
2209             fail("Should throw UnsupportedOperationException when trying to store");
2210         } catch (UnsupportedOperationException success) {
2211         }
2212 
2213         try {
2214             mKeyStore.store(sink, "blah".toCharArray());
2215             fail("Should throw UnsupportedOperationException when trying to store");
2216         } catch (UnsupportedOperationException success) {
2217         }
2218     }
2219 
testKeyStore_KeyOperations_Wrap_Unencrypted_Success()2220     public void testKeyStore_KeyOperations_Wrap_Unencrypted_Success() throws Exception {
2221         mKeyStore.load(null, null);
2222 
2223         mKeyStore.setEntry(TEST_ALIAS_1, makeUserRsaKey1(), null);
2224 
2225         // Test key usage
2226         Entry e = mKeyStore.getEntry(TEST_ALIAS_1, null);
2227         assertNotNull(e);
2228         assertTrue(e instanceof PrivateKeyEntry);
2229 
2230         PrivateKeyEntry privEntry = (PrivateKeyEntry) e;
2231         PrivateKey privKey = privEntry.getPrivateKey();
2232         assertNotNull(privKey);
2233 
2234         PublicKey pubKey = privEntry.getCertificate().getPublicKey();
2235 
2236         Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding");
2237         c.init(Cipher.WRAP_MODE, pubKey);
2238 
2239         byte[] expectedKey = new byte[] {
2240                 0x00, 0x05, (byte) 0xAA, (byte) 0x0A5, (byte) 0xFF, 0x55, 0x0A
2241         };
2242 
2243         SecretKey expectedSecret = new SecretKeySpec(expectedKey, "AES");
2244 
2245         byte[] wrappedExpected = c.wrap(expectedSecret);
2246 
2247         c.init(Cipher.UNWRAP_MODE, privKey);
2248         SecretKey actualSecret = (SecretKey) c.unwrap(wrappedExpected, "AES", Cipher.SECRET_KEY);
2249 
2250         assertEquals(Arrays.toString(expectedSecret.getEncoded()),
2251                 Arrays.toString(actualSecret.getEncoded()));
2252     }
2253 }
2254