@@ -37,7 +37,6 @@ public void ImportPrivateKey_with_PrivateKey_Succeeds_and_HasExpectedValues(
37
37
StandardTestDevice testDeviceType )
38
38
{
39
39
// Arrange
40
- var testDevice = IntegrationTestDeviceEnumeration . GetTestDevice ( testDeviceType ) ;
41
40
var ( testPublicKey , testPrivateKey ) = TestKeys . GetKeyPair ( keyType ) ;
42
41
var testPivPublicKey = testPublicKey . AsPivPublicKey ( ) ;
43
42
var keyParameters = AsnPrivateKeyDecoder . CreatePrivateKey ( testPrivateKey . EncodedKey ) ;
@@ -46,7 +45,7 @@ public void ImportPrivateKey_with_PrivateKey_Succeeds_and_HasExpectedValues(
46
45
const PivTouchPolicy expectedTouchPolicy = PivTouchPolicy . Always ;
47
46
48
47
// Act
49
- using var pivSession = GetSession ( testDevice ) ;
48
+ using var pivSession = GetSession ( testDeviceType ) ;
50
49
pivSession . ImportPrivateKey ( PivSlot . Retired1 , keyParameters , expectedPinPolicy , expectedTouchPolicy ) ;
51
50
52
51
// Assert
@@ -92,74 +91,53 @@ public void ImportPrivateKey_with_PrivateKey_Succeeds_and_HasExpectedValues(
92
91
[ InlineData ( KeyType . RSA2048 , StandardTestDevice . Fw5 ) ]
93
92
[ InlineData ( KeyType . RSA3072 , StandardTestDevice . Fw5 ) ]
94
93
[ InlineData ( KeyType . RSA4096 , StandardTestDevice . Fw5 ) ]
95
- public void KeyAndCertImport (
94
+ public void Import_KeyAndMatchingCert (
96
95
KeyType keyType ,
97
96
StandardTestDevice testDeviceType )
98
97
{
99
- var testDevice = IntegrationTestDeviceEnumeration . GetTestDevice ( testDeviceType ) ;
100
- Assert . True ( testDevice . EnabledUsbCapabilities . HasFlag ( YubiKeyCapabilities . Piv ) ) ;
101
-
102
- using var pivSession = GetSession ( testDevice ) ;
98
+ using var pivSession = GetSession ( testDeviceType ) ;
103
99
104
100
var testPrivateKey = TestKeys . GetTestPrivateKey ( keyType ) ;
105
101
var testCert = TestKeys . GetTestCertificate ( keyType ) ;
106
102
var privateKey = AsnPrivateKeyDecoder . CreatePrivateKey ( testPrivateKey . EncodedKey ) ;
107
103
108
104
pivSession . ImportPrivateKey ( 0x90 , privateKey ) ;
109
- pivSession . ImportCertificate ( 0x90 , testCert . AsX509Certificate2 ( ) ! ) ;
105
+ pivSession . ImportCertificate ( 0x90 , testCert . AsX509Certificate2 ( ) ) ;
110
106
}
111
107
112
108
[ SkippableTheory ( typeof ( NotSupportedException ) , typeof ( DeviceNotFoundException ) ) ]
113
- [ InlineData ( KeyType . RSA1024 , StandardTestDevice . Fw5 ) ]
114
- [ InlineData ( KeyType . RSA2048 , StandardTestDevice . Fw5 ) ]
115
- [ InlineData ( KeyType . RSA3072 , StandardTestDevice . Fw5 ) ]
116
- [ InlineData ( KeyType . RSA4096 , StandardTestDevice . Fw5 ) ]
117
- [ InlineData ( KeyType . ECP256 , StandardTestDevice . Fw5 ) ]
118
- [ InlineData ( KeyType . ECP384 , StandardTestDevice . Fw5 ) ]
119
- [ InlineData ( KeyType . Ed25519 , StandardTestDevice . Fw5 ) ]
120
- public void CertImport (
109
+ [ InlineData ( KeyType . RSA1024 , false ) ]
110
+ [ InlineData ( KeyType . RSA2048 , false ) ]
111
+ [ InlineData ( KeyType . RSA3072 , false ) ]
112
+ [ InlineData ( KeyType . RSA4096 , false ) ]
113
+ [ InlineData ( KeyType . ECP256 , false ) ]
114
+ [ InlineData ( KeyType . ECP384 , false ) ]
115
+ [ InlineData ( KeyType . Ed25519 , false ) ]
116
+ [ InlineData ( KeyType . RSA1024 , true ) ]
117
+ [ InlineData ( KeyType . RSA2048 , true ) ]
118
+ [ InlineData ( KeyType . RSA3072 , true ) ]
119
+ [ InlineData ( KeyType . RSA4096 , true ) ]
120
+ [ InlineData ( KeyType . ECP256 , true ) ]
121
+ [ InlineData ( KeyType . ECP384 , true ) ]
122
+ [ InlineData ( KeyType . Ed25519 , true ) ]
123
+ public void ImportCertificate_ImportedCert_Equals_TestCert (
121
124
KeyType keyType ,
122
- StandardTestDevice testDeviceType )
125
+ bool compressed ,
126
+ StandardTestDevice testDeviceType = StandardTestDevice . Fw5 )
123
127
{
124
- var testDevice = IntegrationTestDeviceEnumeration . GetTestDevice ( testDeviceType ) ;
125
- Assert . True ( testDevice . EnabledUsbCapabilities . HasFlag ( YubiKeyCapabilities . Piv ) ) ;
126
-
127
128
var testCertificate = TestKeys . GetTestCertificate ( keyType ) ;
128
129
var testX509Certificate = testCertificate . AsX509Certificate2 ( ) ;
129
130
130
- using var pivSession = GetSession ( testDevice ) ;
131
- pivSession . ImportCertificate ( 0x90 , testX509Certificate ) ;
131
+ using var pivSession = GetSession ( testDeviceType ) ;
132
+ pivSession . ImportCertificate ( 0x90 , testX509Certificate , compressed ) ;
132
133
133
134
var resultCert = pivSession . GetCertificate ( 0x90 ) ;
134
135
Assert . True ( resultCert . Equals ( testX509Certificate ) ) ;
135
136
}
136
137
137
- [ SkippableTheory ( typeof ( NotSupportedException ) , typeof ( DeviceNotFoundException ) ) ]
138
- [ InlineData ( KeyType . RSA1024 , StandardTestDevice . Fw5 ) ]
139
- [ InlineData ( KeyType . RSA2048 , StandardTestDevice . Fw5 ) ]
140
- [ InlineData ( KeyType . RSA3072 , StandardTestDevice . Fw5 ) ]
141
- [ InlineData ( KeyType . RSA4096 , StandardTestDevice . Fw5 ) ]
142
- [ InlineData ( KeyType . ECP256 , StandardTestDevice . Fw5 ) ]
143
- [ InlineData ( KeyType . ECP384 , StandardTestDevice . Fw5 ) ]
144
- [ InlineData ( KeyType . Ed25519 , StandardTestDevice . Fw5 ) ]
145
- public void ImportCompressedCert ( KeyType keyType , StandardTestDevice testDeviceType )
138
+ private static PivSession GetSession ( StandardTestDevice testDeviceType )
146
139
{
147
140
var testDevice = IntegrationTestDeviceEnumeration . GetTestDevice ( testDeviceType ) ;
148
- Assert . True ( testDevice . EnabledUsbCapabilities . HasFlag ( YubiKeyCapabilities . Piv ) ) ;
149
-
150
- var testCertificate = TestKeys . GetTestCertificate ( keyType ) ;
151
- var testX509Certificate = testCertificate . AsX509Certificate2 ( ) ;
152
-
153
- using var pivSession = GetSession ( testDevice ) ;
154
- pivSession . ImportCertificate ( 0x91 , testX509Certificate , true ) ;
155
-
156
- var resultCert = pivSession . GetCertificate ( 0x91 ) ;
157
- Assert . True ( resultCert . Equals ( testX509Certificate ) ) ;
158
- }
159
-
160
- private static PivSession GetSession (
161
- IYubiKeyDevice testDevice )
162
- {
163
141
var pivSession = new PivSession ( testDevice ) ;
164
142
Assert . True ( testDevice . EnabledUsbCapabilities . HasFlag ( YubiKeyCapabilities . Piv ) ) ;
165
143
0 commit comments