You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
2 months ago
|
using System;
|
||
|
using System.IO;
|
||
|
|
||
|
using Org.BouncyCastle.Crypto;
|
||
|
using Org.BouncyCastle.Crypto.IO;
|
||
|
using Org.BouncyCastle.Utilities.IO;
|
||
|
|
||
|
namespace Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||
|
{
|
||
|
internal sealed class BcVerifyingStreamSigner
|
||
|
: TlsStreamSigner
|
||
|
{
|
||
|
private readonly ISigner m_signer;
|
||
|
private readonly ISigner m_verifier;
|
||
|
private readonly TeeOutputStream m_output;
|
||
|
|
||
|
internal BcVerifyingStreamSigner(ISigner signer, ISigner verifier)
|
||
|
{
|
||
|
Stream outputSigner = new SignerSink(signer);
|
||
|
Stream outputVerifier = new SignerSink(verifier);
|
||
|
|
||
|
this.m_signer = signer;
|
||
|
this.m_verifier = verifier;
|
||
|
this.m_output = new TeeOutputStream(outputSigner, outputVerifier);
|
||
|
}
|
||
|
|
||
|
public Stream GetOutputStream()
|
||
|
{
|
||
|
return m_output;
|
||
|
}
|
||
|
|
||
|
public byte[] GetSignature()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
byte[] signature = m_signer.GenerateSignature();
|
||
|
if (m_verifier.VerifySignature(signature))
|
||
|
return signature;
|
||
|
}
|
||
|
catch (CryptoException e)
|
||
|
{
|
||
|
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||
|
}
|
||
|
|
||
|
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||
|
}
|
||
|
}
|
||
|
}
|