认证与公钥/私钥签名:什么是一个很好的消息(摘要)? [英] Authentication with public/private key signatures: What's a good message (digest)?

查看:200
本文介绍了认证与公钥/私钥签名:什么是一个很好的消息(摘要)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立与客户机/服务器基础架构的应用,并想利用公钥/私钥方法来实现的认证机制。

I'm build an application with a client/server infrastructure and would like to implement an authentication mechanism using the public/private key method.

让我们假设客户机拥有私钥和服务器只有公共密钥。在验证客户签署的消息使用私钥,将其发送到它的使用公钥验证服务器。如果成功通过验证客户端进行身份验证。

Let's assume that a client owns the private key and the server only has the public key. During authentication the client signs a message with the private key, sends it to the server where it's validated with the public key. If validation succeeds the client is authenticated.

下面是一些JUnit测试code,其中我自己熟悉的概念:

Here's some JUnit test code where I made myself familiar with the concepts:

@Test
public void testSignature() throws Exception {
    final String message = "Hello world is a stupid message to be signed";

    final KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();

    final Signature privSig = Signature.getInstance("SHA1withRSA");

    privSig.initSign(keyPair.getPrivate());
    privSig.update(message.getBytes());

    byte[] signature = privSig.sign();

    final Signature pubSig = Signature.getInstance("SHA1withRSA");

    pubSig.initVerify(keyPair.getPublic());
    pubSig.update(message.getBytes());

    assertTrue(pubSig.verify(signature));
}

当然,为了这个工作服务器和客户端必须持有平原消息(摘要)的。

Of course in order for this to work both server and clients must be in possession of the plain message (digest).

现在我的问题是:什么是用于签名的好消息(摘要)?例如可这是一个静态的,硬codeD字符串(用于所有客户端),或将本强加某种安全问题这个概念?如果一个静态字符串是坏的会是协商身份验证之前,一些随机字符串一个好主意?此随机串可以用作例如一个会话键和无效一段时间后

Now my question is: What is a good message (digest) to be used for the signature? For example can this be a static, hardcoded string (which is used for all clients) or would this impose some kind of security issue on this concept? If a static string is bad would it be a good idea to negotiate some random string before authentication? This random string could be used as a "session" key for example and invalidated after some time.

推荐答案

静态字符串会很糟糕,因为它容易受到攻击的重复(签名的字符串将是相同的每一次)。

The static String would be bad since its susceptible to a repeat attack (The signed string would be the same every time).

虽然,你似乎是重塑什么之前已经完成。使用证书是值得信赖的方法。见这个例子就可以了更多的信息: HTTPS的Java客户端证书认证

Although, you seem to be reinventing what has been done before. Using certificates is the trusted way. See this example for more info on it: Java HTTPS client certificate authentication

如果你想自己实现它,你可能会需要在SSL是如何工作的阅读和模仿。任何其他的解决办法很可能有它的一些缺陷,除非它是非常定制(例如,您的客户将继续共享静态字符串1000的,它永远不会重复使用的列表,服务器有同样的名单,并保持跟踪什么已经使用。或替代地,保持跟踪在共享数哪个增量,如在下面的评论建议的)。

If you want to implement it yourself you'll probably need to read up on how SSL works and mimic that. Any other solution is likely to have some flaws in it, unless it was very bespoke (e.g. your client would keep a list of 1000's of shared static strings which it never reused, and the server had that same list and kept track of what had been used. or alternatively, keep track of a shared number which increments, as suggested in the comments below.)

这篇关于认证与公钥/私钥签名:什么是一个很好的消息(摘要)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆