diff --git a/crypto/src/util/ssh/OpenSSHPrivateKeyUtil.cs b/crypto/src/util/ssh/OpenSSHPrivateKeyUtil.cs
index a918d3483..0ddd90773 100644
--- a/crypto/src/util/ssh/OpenSSHPrivateKeyUtil.cs
+++ b/crypto/src/util/ssh/OpenSSHPrivateKeyUtil.cs
@@ -1,9 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
+
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.Pkcs;
@@ -16,17 +12,11 @@ using Org.BouncyCastle.Pkcs;
namespace Org.BouncyCastle.Utilities.SSH
{
- public class OpenSSHPrivateKeyUtil
+ public static class OpenSshPrivateKeyUtilities
{
- private OpenSSHPrivateKeyUtil()
- {
-
- }
-
- /**
- * Magic value for proprietary OpenSSH private key.
- **/
- static readonly byte[] AUTH_MAGIC = Strings.ToByteArray("openssh-key-v1\0"); // C string so null terminated
+ /// <summary>Magic value for proprietary OpenSSH private key.</summary>
+ /// <remarks>C string so null terminated.</remarks>
+ private static readonly byte[] AUTH_MAGIC = Strings.ToByteArray("openssh-key-v1\0");
/**
* Encode a cipher parameters into an OpenSSH private key.
@@ -38,9 +28,7 @@ namespace Org.BouncyCastle.Utilities.SSH
public static byte[] EncodePrivateKey(AsymmetricKeyParameter parameters)
{
if (parameters == null)
- {
- throw new ArgumentException("parameters is null");
- }
+ throw new ArgumentNullException(nameof(parameters));
if (parameters is RsaPrivateCrtKeyParameters || parameters is ECPrivateKeyParameters)
{
@@ -76,7 +64,7 @@ namespace Org.BouncyCastle.Utilities.SSH
{
Ed25519PublicKeyParameters publicKeyParameters = ed25519PrivateKey.GeneratePublicKey();
- SSHBuilder builder = new SSHBuilder();
+ SshBuilder builder = new SshBuilder();
builder.WriteBytes(AUTH_MAGIC);
builder.WriteString("none"); // cipher name
builder.WriteString("none"); // KDF name
@@ -85,12 +73,12 @@ namespace Org.BouncyCastle.Utilities.SSH
builder.U32(1); // Number of keys
{
- byte[] pkEncoded = OpenSSHPublicKeyUtil.EncodePublicKey(publicKeyParameters);
+ byte[] pkEncoded = OpenSshPublicKeyUtilities.EncodePublicKey(publicKeyParameters);
builder.WriteBlock(pkEncoded);
}
{
- SSHBuilder pkBuild = new SSHBuilder();
+ SshBuilder pkBuild = new SshBuilder();
int checkint = CryptoServicesRegistrar.GetSecureRandom().NextInt();
pkBuild.U32((uint)checkint);
@@ -120,10 +108,10 @@ namespace Org.BouncyCastle.Utilities.SSH
/**
* Parse a private key.
- * <p>
+ * <p/>
* This method accepts the body of the OpenSSH private key.
* The easiest way to extract the body is to use PemReader, for example:
- * <p>
+ * <p/>
* byte[] blob = new PemReader([reader]).readPemObject().getContent();
* CipherParameters params = parsePrivateKeyBlob(blob);
*
@@ -187,7 +175,7 @@ namespace Org.BouncyCastle.Utilities.SSH
}
else
{
- SSHBuffer kIn = new SSHBuffer(AUTH_MAGIC, blob);
+ SshBuffer kIn = new SshBuffer(AUTH_MAGIC, blob);
String cipherName = kIn.ReadString();
if (!"none".Equals(cipherName))
@@ -208,7 +196,7 @@ namespace Org.BouncyCastle.Utilities.SSH
}
// Burn off public key.
- OpenSSHPublicKeyUtil.ParsePublicKey(kIn.ReadBlock());
+ OpenSshPublicKeyUtilities.ParsePublicKey(kIn.ReadBlock());
byte[] privateKeyBlock = kIn.ReadPaddedBlock();
@@ -217,7 +205,7 @@ namespace Org.BouncyCastle.Utilities.SSH
throw new InvalidOperationException("decoded key has trailing data");
}
- SSHBuffer pkIn = new SSHBuffer(privateKeyBlock);
+ SshBuffer pkIn = new SshBuffer(privateKeyBlock);
int check1 = pkIn.ReadU32();
int check2 = pkIn.ReadU32();
@@ -243,7 +231,7 @@ namespace Org.BouncyCastle.Utilities.SSH
}
else if (keyType.StartsWith("ecdsa"))
{
- DerObjectIdentifier oid = SSHNamedCurves.GetByName(Strings.FromByteArray(pkIn.ReadBlock())) ??
+ DerObjectIdentifier oid = SshNamedCurves.GetByName(Strings.FromByteArray(pkIn.ReadBlock())) ??
throw new InvalidOperationException("OID not found for: " + keyType);
X9ECParameters curveParams = NistNamedCurves.GetByOid(oid) ?? throw new InvalidOperationException("Curve not found for: " + oid);
diff --git a/crypto/src/util/ssh/OpenSSHPublicKeyUtil.cs b/crypto/src/util/ssh/OpenSSHPublicKeyUtil.cs
index 8f1fa8ec1..02e6928e0 100644
--- a/crypto/src/util/ssh/OpenSSHPublicKeyUtil.cs
+++ b/crypto/src/util/ssh/OpenSSHPublicKeyUtil.cs
@@ -1,25 +1,15 @@
-using Org.BouncyCastle.Asn1;
+using System;
+
+using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
-using Org.BouncyCastle.Math.EC;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
namespace Org.BouncyCastle.Utilities.SSH
{
- public class OpenSSHPublicKeyUtil
+ public static class OpenSshPublicKeyUtilities
{
- private OpenSSHPublicKeyUtil()
- {
-
- }
-
private static readonly String RSA = "ssh-rsa";
private static readonly String ECDSA = "ecdsa";
private static readonly String ED_25519 = "ssh-ed25519";
@@ -27,7 +17,7 @@ namespace Org.BouncyCastle.Utilities.SSH
/**
* Parse a public key.
- * <p>
+ * <p/>
* This method accepts the bytes that are Base64 encoded in an OpenSSH public key file.
*
* @param encoded The key.
@@ -35,7 +25,7 @@ namespace Org.BouncyCastle.Utilities.SSH
*/
public static AsymmetricKeyParameter ParsePublicKey(byte[] encoded)
{
- SSHBuffer buffer = new SSHBuffer(encoded);
+ SshBuffer buffer = new SshBuffer(encoded);
return ParsePublicKey(buffer);
}
@@ -62,7 +52,7 @@ namespace Org.BouncyCastle.Utilities.SSH
RsaKeyParameters rsaPubKey = (RsaKeyParameters)cipherParameters;
- SSHBuilder builder = new SSHBuilder();
+ SshBuilder builder = new SshBuilder();
builder.WriteString(RSA);
builder.WriteBigNum(rsaPubKey.Exponent);
builder.WriteBigNum(rsaPubKey.Modulus);
@@ -72,12 +62,12 @@ namespace Org.BouncyCastle.Utilities.SSH
}
else if (cipherParameters is ECPublicKeyParameters ecPublicKey)
{
- SSHBuilder builder = new SSHBuilder();
+ SshBuilder builder = new SshBuilder();
//
// checked for named curve parameters..
//
- String name = SSHNamedCurves.GetNameForParameters(ecPublicKey.Parameters);
+ String name = SshNamedCurves.GetNameForParameters(ecPublicKey.Parameters);
if (name == null)
{
@@ -93,7 +83,7 @@ namespace Org.BouncyCastle.Utilities.SSH
{
DsaParameters dsaParams = dsaPubKey.Parameters;
- SSHBuilder builder = new SSHBuilder();
+ SshBuilder builder = new SshBuilder();
builder.WriteString(DSS);
builder.WriteBigNum(dsaParams.P);
builder.WriteBigNum(dsaParams.Q);
@@ -103,7 +93,7 @@ namespace Org.BouncyCastle.Utilities.SSH
}
else if (cipherParameters is Ed25519PublicKeyParameters ed25519PublicKey)
{
- SSHBuilder builder = new SSHBuilder();
+ SshBuilder builder = new SshBuilder();
builder.WriteString(ED_25519);
builder.WriteBlock(ed25519PublicKey.GetEncoded());
return builder.GetBytes();
@@ -118,7 +108,7 @@ namespace Org.BouncyCastle.Utilities.SSH
* @param buffer containing the SSH public key.
* @return A CipherParameters instance.
*/
- public static AsymmetricKeyParameter ParsePublicKey(SSHBuffer buffer)
+ private static AsymmetricKeyParameter ParsePublicKey(SshBuffer buffer)
{
AsymmetricKeyParameter result = null;
@@ -141,8 +131,8 @@ namespace Org.BouncyCastle.Utilities.SSH
else if (magic.StartsWith(ECDSA))
{
String curveName = buffer.ReadString();
- DerObjectIdentifier oid = SSHNamedCurves.GetByName(curveName);
- X9ECParameters x9ECParameters = SSHNamedCurves.GetParameters(oid) ??
+ DerObjectIdentifier oid = SshNamedCurves.GetByName(curveName);
+ X9ECParameters x9ECParameters = SshNamedCurves.GetParameters(oid) ??
throw new InvalidOperationException("unable to find curve for " + magic + " using curve name " + curveName);
var curve = x9ECParameters.Curve;
byte[] pointRaw = buffer.ReadBlock();
diff --git a/crypto/src/util/ssh/SSHBuffer.cs b/crypto/src/util/ssh/SSHBuffer.cs
index 8d3c3f977..795641032 100644
--- a/crypto/src/util/ssh/SSHBuffer.cs
+++ b/crypto/src/util/ssh/SSHBuffer.cs
@@ -1,14 +1,15 @@
using System;
+
using Org.BouncyCastle.Math;
namespace Org.BouncyCastle.Utilities.SSH
{
- public class SSHBuffer
+ internal class SshBuffer
{
private readonly byte[] buffer;
private int pos = 0;
- public SSHBuffer(byte[] magic, byte[] buffer)
+ internal SshBuffer(byte[] magic, byte[] buffer)
{
this.buffer = buffer;
for (int i = 0; i != magic.Length; i++)
@@ -22,7 +23,7 @@ namespace Org.BouncyCastle.Utilities.SSH
pos += magic.Length;
}
- public SSHBuffer(byte[] buffer)
+ internal SshBuffer(byte[] buffer)
{
this.buffer = buffer;
}
diff --git a/crypto/src/util/ssh/SSHBuilder.cs b/crypto/src/util/ssh/SSHBuilder.cs
index 5fa92de4b..24121d0d8 100644
--- a/crypto/src/util/ssh/SSHBuilder.cs
+++ b/crypto/src/util/ssh/SSHBuilder.cs
@@ -1,18 +1,14 @@
using System;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+
using Org.BouncyCastle.Math;
namespace Org.BouncyCastle.Utilities.SSH
{
- public class SSHBuilder
+ internal class SshBuilder
{
private readonly MemoryStream bos = new MemoryStream();
- [CLSCompliant(false)]
public void U32(uint value)
{
bos.WriteByte(Convert.ToByte((value >> 24) & 0xFF));
diff --git a/crypto/src/util/ssh/SSHNamedCurves.cs b/crypto/src/util/ssh/SSHNamedCurves.cs
index 31c350128..6839627b8 100644
--- a/crypto/src/util/ssh/SSHNamedCurves.cs
+++ b/crypto/src/util/ssh/SSHNamedCurves.cs
@@ -1,20 +1,17 @@
-using Org.BouncyCastle.Asn1;
+using System.Collections.Generic;
+using System.Linq;
+
+using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.Sec;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.EC;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math.EC;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Org.BouncyCastle.Utilities.SSH
{
- public class SSHNamedCurves
+ public class SshNamedCurves
{
private static readonly Dictionary<string, DerObjectIdentifier> OidMap =
new Dictionary<string, DerObjectIdentifier>
|