示例#1
0
        public static GoProofs GenerateProofs(int version, string username, SecureString password, string salt,
                                              string signedModulus, string serverEphemeral, int bitLength = 2048)
        {
            byte[] bytes;

            using (GoString goUsername = username.ToGoString())
                using (DisposableGoBytes goPassword = password.ToDisposableGoBytes())
                    using (GoString goSalt = salt.ToGoString())
                        using (GoString goModulus = signedModulus.ToGoString())
                            using (GoString goEphemeral = serverEphemeral.ToGoString())
                            {
                                bytes = NativeGenerateProofs(version, goUsername, goPassword, goSalt, goModulus, goEphemeral, bitLength)
                                        .ConvertToBytes();
                            }

            using (var memStream = new MemoryStream(bytes))
            {
                var reader = new BinaryReader(memStream);
                reader.ReadByte();
                byte type = reader.ReadByte();

                if (type == 0)
                {
                    ushort size = reader.ReadUInt16();
                    byte[] bmsg = reader.ReadBytes(size);
                    throw new Exception("go-srp: " + Encoding.UTF8.GetString(bmsg));
                }

                if (type == 1)
                {
                    ushort size        = reader.ReadUInt16();
                    byte[] clientProof = reader.ReadBytes(size);
                    size = reader.ReadUInt16();
                    byte[] clientEphemeral = reader.ReadBytes(size);
                    size = reader.ReadUInt16();
                    byte[] expectedServerProof = reader.ReadBytes(size);

                    return(new GoProofs
                    {
                        ClientProof = clientProof,
                        ClientEphemeral = clientEphemeral,
                        ExpectedServerProof = expectedServerProof
                    });
                }
            }

            return(null);
        }
示例#2
0
 private static extern GoBytes NativeGenerateProofs(int version, GoString username, DisposableGoBytes password,
                                                    GoString salt, GoString signedModulus, GoString serverEphemeral, int bits);