- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将充气城堡用于 DTLS 握手
。
我按照 this link 生成了 key .我正在通过扩展 DefaultTlsClient 来工作。它可以生成client_hello 数据包。但是当 server_hello 数据包到达时,它给出 org.bouncycaSTLe.crypto.tls.TlsFatalAlert: internal_error(80)
Caused by: java.lang.IllegalArgumentException: unknown HashAlgorithm
。谁能给出任何提示?
Update:
From Wireshark: In the Certificate Request, there are 9 Signature Hash Algorithms. One of them isrsa_pss_sha256(0x0804)
. In thepublic static Digest createHash(short hashAlgorithm)
function inTlsUtils.java
there is no matching for it. That's why it is giving Unknown hash Algorithm. What does that mean? Using Bouncy Castle, is it possible to establish DTLS with that server?
这是加载 keystore 的代码:
public static void initKeyStore() {
char password[] = "bbtone".toCharArray();
if( !isKeystoreLoaded) {
try {
FileInputStream fis = new FileInputStream("bbtone");
KeyMgmt key = new KeyMgmt();
key.open(fis, password);
fis.close();
crt = key.getCRT("bbtone").getEncoded();
fingerprintSHA256 = KeyMgmt.fingerprintSHA256(crt);
ArrayList<byte[]> chain = new ArrayList<byte[]>();
chain.add(crt);
java.security.cert.Certificate root = key.getCRT("root");
if (root != null) {
chain.add(root.getEncoded());
}
privateKey = key.getKEY("bbtone", password).getEncoded();
initDTLS(chain, privateKey, false);
isKeystoreLoaded = true;
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}
生成私钥和证书:
public static boolean initDTLS(java.util.List<byte []> certChain, byte privateKey[], boolean pkRSA) {
try {
org.bouncycastle.asn1.x509.Certificate x509certs[] = new org.bouncycastle.asn1.x509.Certificate[certChain.size()];
for (int i = 0; i < certChain.size(); ++i) {
x509certs[i] = org.bouncycastle.asn1.x509.Certificate.getInstance(certChain.get(i));
}
dtlsCertChain = new org.bouncycastle.crypto.tls.Certificate(x509certs);
if (pkRSA) {
RSAPrivateKey rsa = RSAPrivateKey.getInstance(privateKey);
dtlsPrivateKey = new RSAPrivateCrtKeyParameters(rsa.getModulus(), rsa.getPublicExponent(),
rsa.getPrivateExponent(), rsa.getPrime1(), rsa.getPrime2(), rsa.getExponent1(),
rsa.getExponent2(), rsa.getCoefficient());
} else {
dtlsPrivateKey = PrivateKeyFactory.createKey(privateKey);
}
return true;
} catch (Exception e) {
return false;
}
}
开始DTLS握手:
public void startDTLS() {
socket.connect(recvPacket.getAddress(), recvPacket.getPort());
try {
dtlsClient = new DTLSClientProtocol(new SecureRandom());
} catch (Exception e) {
e.printStackTrace();
dtlsClient = null;
return;
}
tlsClient = new DefaultTlsClient2() {
protected TlsSession session;
public TlsSession getSessionToResume()
{
return this.session;
}
public ProtocolVersion getClientVersion() {
return ProtocolVersion.DTLSv12;
}
public ProtocolVersion getMinimumVersion() {
return ProtocolVersion.DTLSv10;
}
public Hashtable getClientExtensions() throws IOException {
//see : http://bouncy-castle.1462172.n4.nabble.com/DTLS-SRTP-with-bouncycastle-1-49-td4656286.html
logger.debug("Extending getClientExtensions\n");
Hashtable table = super.getClientExtensions();
if (table == null) table = new Hashtable();
//adding the protection profiles
int[] protectionProfiles = {
SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80 //this is the only one supported for now
// SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32
// SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_32
// SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_80
};
byte mki[] = new byte[0]; //do not use mki
UseSRTPData srtpData = new UseSRTPData(protectionProfiles, mki);
TlsSRTPUtils.addUseSRTPExtension(table, srtpData);
return table;
}
public TlsAuthentication getAuthentication() throws IOException {
return new TlsAuthentication() {
public void notifyServerCertificate(org.bouncycastle.crypto.tls.Certificate serverCertificate)
throws IOException
{
//info only
}
public TlsCredentials getClientCredentials(CertificateRequest certificateRequest)
throws IOException
{
short[] certificateTypes = certificateRequest.getCertificateTypes();
if (certificateTypes == null) return null;
boolean ok = false;
for(int a=0;a<certificateTypes.length;a++) {
if (certificateTypes[a] == ClientCertificateType.rsa_sign) {
ok = true;
break;
}
}
if (!ok) return null;
SignatureAndHashAlgorithm signatureAndHashAlgorithm = null;
Vector sigAlgs = certificateRequest.getSupportedSignatureAlgorithms();
if (sigAlgs != null)
{
for (int i = 0; i < sigAlgs.size(); ++i)
{
SignatureAndHashAlgorithm sigAlg = (SignatureAndHashAlgorithm) sigAlgs.elementAt(i);
if (sigAlg.getSignature() == SignatureAlgorithm.rsa)
{
signatureAndHashAlgorithm = sigAlg;
break;
}
}
if (signatureAndHashAlgorithm == null)
{
return null;
}
}
return new DefaultTlsSignerCredentials(context, dtlsCertChain, dtlsPrivateKey, signatureAndHashAlgorithm);
}
};
}
public void notifyHandshakeComplete() throws IOException
{
logger.debug("SRTPChannel:DTLS:Client:Handshake complete");
super.notifyHandshakeComplete();
TlsSession newSession = context.getResumableSession();
if (newSession != null)
{
this.session = newSession;
}
getKeys();
}
};
try {
logger.debug("SRTPChannel:connecting to DTLS server");
dtlsTransport = dtlsClient.connect(tlsClient, new UDPTransport(socket, 1500 - 20 - 8));
} catch (Exception e) {
e.printStackTrace();
}
}
错误:
org.bouncycastle.crypto.tls.TlsFatalAlert: internal_error(80)
at org.bouncycastle.crypto.tls.DTLSClientProtocol.connect(DTLSClientProtocol.java:75)
at processor.ClientMediaHandler.startDTLS(ClientMediaHandler.java:459)
at processor.ClientMediaHandler.run(ClientMediaHandler.java:538)
Caused by: java.lang.IllegalArgumentException: unknown HashAlgorithm
at org.bouncycastle.crypto.tls.TlsUtils.createHash(TlsUtils.java:1184)
at org.bouncycastle.crypto.tls.DeferredHash.checkTrackingHash(DeferredHash.java:203)
at org.bouncycastle.crypto.tls.DeferredHash.trackHashAlgorithm(DeferredHash.java:68)
at org.bouncycastle.crypto.tls.TlsUtils.trackHashAlgorithms(TlsUtils.java:1358)
at org.bouncycastle.crypto.tls.DTLSClientProtocol.clientHandshake(DTLSClientProtocol.java:241)
at org.bouncycastle.crypto.tls.DTLSClientProtocol.connect(DTLSClientProtocol.java:60)
... 2 more
最佳答案
我已经使用 DTLS1.0
解决了这个问题。它现在可以完成握手。
我换了
public ProtocolVersion getClientVersion() {
return ProtocolVersion.DTLSv12;
}
使用以下代码:
public ProtocolVersion getClientVersion() {
return ProtocolVersion.DTLSv10;
}
关于java - 充气城堡给出未知的 HashAlgorithm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49965021/
我正在尝试将充气城堡用于 DTLS 握手。 我按照 this link 生成了 key .我正在通过扩展 DefaultTlsClient 来工作。它可以生成client_hello 数据包。但是当
我无法得到关于这个问题的明确答案,所以这个问题。过去很少有 SO 帖子提到 HashAlgorithm 的实例在 MSDN 文档中不是线程安全的引用片段。 见 Why does SHA1.Comput
从 HashAlgorithm 派生的对象(例如 MD5CryptoServiceProvider)具有 Dispose() 方法,但它是私有(private)的。相反,它有一个 Clear() 方法
我有一个散列算法对象(在本例中为 SHA1),我向其提供数据,以便在调用 Result 属性时最终获得散列结果。 问题是一旦调用了 m_HashAlgorithm.Hash 属性,该对象就不能再用于喂
我需要独立计算多个数据 block 的哈希值。像这样: using( HashAlgorithm hasher = new ActualHashAlgorithm() ) { for( int
使用时 MD5CryptoServiceProvider我发现它可能需要处理,因为它继承自 HashAlgorithm实现 IDisposable 的类.然而,the example in the d
方法 HashAlgorithm.TransformBlock 接受参数 outputBuffer和 outputOffset . 我想不出这个方法有这些的原因。将散列数据复制到某个地方以至于该副本成
我有以下用例: 从一个文件中读取n个字节 计算这 n 个字节的 (MD5) 散列 从文件中读取下m个字节 为最多 n+m 字节的文件计算 (MD5) 哈希 增量散列文件不是问题,just call T
所以我想知道哈希算法的各种实现之间是否存在重大差异,以SHA系列算法为例。它们每个都有 3 个实现,1 个在托管代码中,2 个围绕不同的 native 加密 API 进行包装,但是使用它们之间有什么主
我似乎看到 SHA-2 以两种不同的方式完成。 是的,我知道 1 是“新的”(实例化的),而另一个是 Create 方法,但它似乎实现了相同的相同对象 HashAlgorithm sha2 = new
我需要在 C# 中使用 salt 对密码进行哈希处理。 salt是从一个来源获取的,类型是byte[],password是从另一个来源获取的,类型是String。 计算一个区 block 的哈希值非常
我想了解散列算法的工作原理,特别是 SHA3-512。为了了解它是如何工作的,我在 Google 中搜索了代码并找到了 Hashlib。 .该代码不起作用,因为我没有 Hashlib 库(不确定应该调
这两个代码块返回相同的东西吗?假设 arr 在两个例子中都是相同的 byte[]: 代码示例 1 HashAlgorithm a = HashAlgorithm.Create("SHA-256");
这两个代码块返回相同的东西吗?假设 arr 在两个例子中都是相同的 byte[]: 代码示例 1 HashAlgorithm a = HashAlgorithm.Create("SHA-256");
我正在使用 spymemcached 和 HashAlgorithm.KETAMA_HASH 连接到 5 个节点的 memcached 池。 我的理解是,当我们使用一致的哈希算法时,例如,当节点关闭时
HashAlgorithm.TransformBlock() 具有 outputBuffer 参数,该参数记录为 用于计算哈希码的输入数组部分的副本。 这听起来像是我的数据将被读取,用于更改哈希机制状
我有一个 ASP.Net MVC 项目,它在使用 HashAlgorithm 时运行良好,但我试图在 ASP.NET Core 2 中复制同一个项目,但出现以下错误: System.PlatformN
我是一名优秀的程序员,十分优秀!