You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Use System.Security.Cryptography for DSA
This is the analogue of the RSA change #1373 for DSA. This has a couple of caveats:
- The BCL supports only FIPS 186-compliant keys, that is, public (P, Q) lengths
of (512 <= P <= 1024, 160) for FIPS 186-1/186-2; and (2048, 256), (3072, 256)
for FIPS 186-3/186-4. The latter also specifies (2048, 224) but due to a quirk
in the Windows API, the BCL does not support Q values of length 224[^1].
- OpenSSH, based on the SSH spec, only supports (supported) Q values of length 160,
but appears to also work in non-FIPS-compliant cases such as in our integration
tests with a (2048, 160) host key. That test now fails and I changed that host key
to (1024, 160).
This basically means that (1024, 160) is the largest DSA key size supported by both
SSH.NET and OpenSSH. However, given that OpenSSH deprecated DSA in 2015[^2], and the
alternative that I have been considering is just to delete support for DSA in the
library, this change seems reasonable to me. I don't think we can justify keeping the
current handwritten code around.
I think we may still consider dropping DSA from the library, I just had this branch
laying around and figured I'd finish it off.
[^1]: https://github.com/dotnet/runtime/blob/fadd8313653f71abd0068c8bf914be88edb2c8d3/src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs#L259-L265
[^2]: https://www.openssh.com/txt/release-7.0
* Appease mono
* test experiment
* Revert "Appease mono"
This reverts commit 881eefe.
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
176
85
protectedvirtualvoidDispose(booldisposing)
177
86
{
178
-
if(_isDisposed)
179
-
{
180
-
return;
181
-
}
182
-
183
-
if(disposing)
184
-
{
185
-
varhash=_hash;
186
-
if(hash!=null)
187
-
{
188
-
hash.Dispose();
189
-
_hash=null;
190
-
}
191
-
192
-
_isDisposed=true;
193
-
}
194
-
}
195
-
196
-
/// <summary>
197
-
/// Finalizes an instance of the <see cref="DsaDigitalSignature"/> class.
@@ -147,6 +154,54 @@ public DsaKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y, BigInteger
147
154
G=g;
148
155
Y=y;
149
156
X=x;
157
+
158
+
DSA=LoadDSA();
159
+
}
160
+
161
+
#pragma warning disable CA1859// Use concrete types when possible for improved performance
162
+
#pragma warning disable CA5384// Do Not Use Digital Signature Algorithm (DSA)
163
+
privateDSALoadDSA()
164
+
{
165
+
#if NETFRAMEWORK
166
+
// On .NET Framework we use the concrete CNG type which is FIPS-186-3
167
+
// compatible. The CryptoServiceProvider type returned by DSA.Create()
168
+
// is limited to FIPS-186-1 (max 1024 bit key).
169
+
vardsa=newDSACng();
170
+
#else
171
+
vardsa=DSA.Create();
172
+
#endif
173
+
dsa.ImportParameters(GetDSAParameters());
174
+
175
+
returndsa;
176
+
}
177
+
#pragma warning restore CA5384// Do Not Use Digital Signature Algorithm (DSA)
178
+
#pragma warning restore CA1859// Use concrete types when possible for improved performance
179
+
180
+
internalDSAParametersGetDSAParameters()
181
+
{
182
+
// P, G, Y, Q are required.
183
+
// P, G, Y must have the same length.
184
+
// If X is present, it must have the same length as Q.
185
+
186
+
// See https://github.com/dotnet/runtime/blob/fadd8313653f71abd0068c8bf914be88edb2c8d3/src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs#L23
187
+
// and https://github.com/dotnet/runtime/blob/fadd8313653f71abd0068c8bf914be88edb2c8d3/src/libraries/Common/src/System/Security/Cryptography/DSAKeyFormatHelper.cs#L18
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
165
220
protectedvirtualvoidDispose(booldisposing)
166
221
{
167
-
if(_isDisposed)
168
-
{
169
-
return;
170
-
}
171
-
172
222
if(disposing)
173
223
{
174
-
vardigitalSignature=_digitalSignature;
175
-
if(digitalSignature!=null)
176
-
{
177
-
digitalSignature.Dispose();
178
-
_digitalSignature=null;
179
-
}
180
-
181
-
_isDisposed=true;
224
+
_digitalSignature?.Dispose();
225
+
DSA.Dispose();
182
226
}
183
227
}
184
-
185
-
/// <summary>
186
-
/// Finalizes an instance of the <see cref="DsaKey"/> class.
0 commit comments