@@ -32,8 +32,6 @@ public void Attest_EmptySlot_ThrowsException(
32
32
{
33
33
TestDeviceType = deviceType ;
34
34
35
- LoadAttestationPair ( KeyType . ECP256 , true ) ;
36
-
37
35
_ = Assert . Throws < InvalidOperationException > ( ( ) =>
38
36
Session . CreateAttestationStatement ( PivSlot . Authentication ) ) ;
39
37
}
@@ -44,15 +42,13 @@ public void Attest_Imported_ThrowsException(
44
42
StandardTestDevice deviceType )
45
43
{
46
44
TestDeviceType = deviceType ;
45
+ var privateKey = TestKeys . GetTestPrivateKey ( KeyType . ECP384 ) . AsPrivateKey ( ) ;
47
46
48
- LoadAttestationPair ( KeyType . ECP384 , true ) ;
49
- PivSupport . ResetPiv ( Session ) ;
50
-
51
- var isValid = PivSupport . ImportKey ( Session , PivSlot . Authentication ) ;
52
- Assert . True ( isValid ) ;
47
+ Session . ImportPrivateKey ( PivSlot . Retired1 , privateKey ) ;
53
48
49
+ // Cannot attest to an imported key.
54
50
_ = Assert . Throws < InvalidOperationException > ( ( ) =>
55
- Session . CreateAttestationStatement ( PivSlot . Authentication ) ) ;
51
+ Session . CreateAttestationStatement ( PivSlot . Retired1 ) ) ;
56
52
}
57
53
58
54
[ Theory ]
@@ -66,30 +62,20 @@ public void AttestGenerated(
66
62
StandardTestDevice deviceType )
67
63
{
68
64
TestDeviceType = deviceType ;
69
- byte [ ] slotNumbers =
70
- {
71
- 0x9A , 0x9C , 0x9D , 0x9E ,
72
- 0x82 , 0x83 , 0x84 , 0x85 , 0x86 , 0x87 , 0x88 , 0x89 , 0x8A , 0x8B , 0x8C , 0x8D , 0x8E , 0x8F ,
73
- 0x90 , 0x91 , 0x92 , 0x93 , 0x94 , 0x95
74
- } ;
75
65
76
- LoadAttestationPair ( keyType , true ) ;
66
+ const byte slotNumber = PivSlot . Retired1 ;
67
+ _ = Session . GenerateKeyPair (
68
+ slotNumber , keyType , PivPinPolicy . Never , PivTouchPolicy . Never ) ;
77
69
78
- foreach ( var slotNumber in slotNumbers )
70
+ X509Certificate2 ? cert = null ;
71
+ try
79
72
{
80
- _ = Session . GenerateKeyPair (
81
- slotNumber , KeyType . ECP256 , PivPinPolicy . Never , PivTouchPolicy . Never ) ;
82
-
83
- X509Certificate2 ? cert = null ;
84
- try
85
- {
86
- cert = Session . CreateAttestationStatement ( slotNumber ) ;
87
- Assert . NotEqual ( 1 , cert . Version ) ;
88
- }
89
- finally
90
- {
91
- cert ? . Dispose ( ) ;
92
- }
73
+ cert = Session . CreateAttestationStatement ( slotNumber ) ;
74
+ Assert . NotEqual ( 1 , cert . Version ) ;
75
+ }
76
+ finally
77
+ {
78
+ cert ? . Dispose ( ) ;
93
79
}
94
80
}
95
81
@@ -135,16 +121,18 @@ public void GetAttestationCert_ReturnsCert(
135
121
[ InlineData ( BadAttestationPairs . KeyEccP256CertVersion1 , StandardTestDevice . Fw5 ) ]
136
122
[ InlineData ( BadAttestationPairs . KeyEccP384CertVersion1 , StandardTestDevice . Fw5 ) ]
137
123
[ InlineData ( BadAttestationPairs . KeyRsa2048CertBigName , StandardTestDevice . Fw5 ) ]
138
- public void UseBadAttestPair_CreateStatement_ThrowsInvalidOp ( int whichPair , StandardTestDevice deviceType )
124
+ public void UseBadAttestPair_CreateStatement_ThrowsInvalidOp (
125
+ int whichPair ,
126
+ StandardTestDevice deviceType )
139
127
{
140
128
TestDeviceType = deviceType ;
141
129
BadAttestationPairs . GetPair ( whichPair , out var privateKeyPem , out var certPem ) ;
142
-
130
+
143
131
var certObj = X509CertificateLoader . LoadCertificate ( PemHelper . GetBytesFromPem ( certPem ) ) ;
144
132
var privateKey = AsnPrivateKeyDecoder . CreatePrivateKey ( PemHelper . GetBytesFromPem ( privateKeyPem ) ) ;
145
133
var isValid = LoadAttestationPairCommands ( privateKey , certObj ) ;
146
134
Assert . True ( isValid ) ;
147
-
135
+
148
136
isValid = AttestationShouldFail ( BadAttestationPairs . KeyRsa1024CertValid ) ;
149
137
Assert . True ( isValid ) ;
150
138
}
@@ -216,7 +204,7 @@ private void LoadAttestationPair(
216
204
var testCert = TestKeys . GetTestCertificate ( keyType , isValidCert ) ;
217
205
var testPrivKey = TestKeys . GetTestPrivateKey ( keyType ) ;
218
206
var privateKey = testPrivKey . AsPrivateKey ( ) ;
219
-
207
+
220
208
Session . ReplaceAttestationKeyAndCertificate ( privateKey , testCert . AsX509Certificate2 ( ) ) ;
221
209
}
222
210
}
0 commit comments