Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JDChain
Bftsmart
提交
7efcf90d
B
Bftsmart
项目概览
JDChain
/
Bftsmart
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Bftsmart
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7efcf90d
编写于
5月 17, 2011
作者:
B
bessani@gmail.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Safely paralelizes signature verification from different clients to exploit multicore machines.
上级
feb6ddd6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
158 addition
and
35 deletion
+158
-35
src/navigators/smart/clientsmanagement/ClientData.java
src/navigators/smart/clientsmanagement/ClientData.java
+28
-12
src/navigators/smart/clientsmanagement/ClientsManager.java
src/navigators/smart/clientsmanagement/ClientsManager.java
+7
-3
src/navigators/smart/tom/core/TOMLayer.java
src/navigators/smart/tom/core/TOMLayer.java
+2
-4
src/navigators/smart/tom/util/SignatureTest.java
src/navigators/smart/tom/util/SignatureTest.java
+86
-0
src/navigators/smart/tom/util/TOMUtil.java
src/navigators/smart/tom/util/TOMUtil.java
+35
-16
未找到文件。
src/navigators/smart/clientsmanagement/ClientData.java
浏览文件 @
7efcf90d
...
...
@@ -18,11 +18,14 @@
package
navigators.smart.clientsmanagement
;
import
java.security.PublicKey
;
import
java.security.Signature
;
import
java.security.SignatureException
;
import
java.util.Iterator
;
import
java.util.concurrent.locks.ReentrantLock
;
import
navigators.smart.reconfiguration.ReconfigurationManager
;
import
navigators.smart.tom.core.messages.TOMMessage
;
import
navigators.smart.tom.util.Logger
;
import
navigators.smart.tom.util.TOMUtil
;
public
class
ClientData
{
...
...
@@ -43,15 +46,26 @@ public class ClientData {
private
TOMMessage
lastReplySent
=
null
;
private
ReconfigurationManager
manager
;
private
Signature
signatureVerificator
=
null
;
/**
* Class constructor. Just store the clientId.
* Class constructor. Just store the clientId and creates a signature
* verificator for a given client public key.
*
* @param clientId
* @param clientId client unique id
* @param publicKey client public key
*/
public
ClientData
(
int
clientId
,
ReconfigurationManager
manager
)
{
public
ClientData
(
int
clientId
,
PublicKey
publicKey
)
{
this
.
clientId
=
clientId
;
this
.
manager
=
manager
;
if
(
publicKey
!=
null
)
{
try
{
signatureVerificator
=
Signature
.
getInstance
(
"SHA1withRSA"
);
signatureVerificator
.
initVerify
(
publicKey
);
Logger
.
println
(
"Signature verifier initialized for client "
+
clientId
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
public
int
getClientId
()
{
...
...
@@ -79,12 +93,14 @@ public class ClientData {
}*/
public
boolean
verifySignature
(
byte
[]
message
,
byte
[]
signature
)
{
//******* EDUARDO BEGIN **************//
return
TOMUtil
.
verifySignature
(
manager
.
getStaticConf
().
getRSAPublicKey
(
clientId
),
message
,
signature
);
//******* EDUARDO END **************//
if
(
signatureVerificator
!=
null
)
{
try
{
return
TOMUtil
.
verifySignature
(
signatureVerificator
,
message
,
signature
);
}
catch
(
SignatureException
ex
)
{
ex
.
printStackTrace
();
}
}
return
false
;
}
public
void
setLastMessageExecuted
(
int
lastMessageExecuted
)
{
...
...
src/navigators/smart/clientsmanagement/ClientsManager.java
浏览文件 @
7efcf90d
...
...
@@ -64,9 +64,13 @@ public class ClientsManager {
if
(
clientData
==
null
)
{
Logger
.
println
(
"(ClientsManager.getClientData) Creating new client data, client id="
+
clientId
);
//******* EDUARDO BEGIN **************//
clientData
=
new
ClientData
(
clientId
,
manager
);
//******* EDUARDO END **************//
//******* EDUARDO BEGIN **************//
clientData
=
new
ClientData
(
clientId
,
(
manager
.
getStaticConf
().
getUseSignatures
()
==
1
)?
manager
.
getStaticConf
().
getRSAPublicKey
(
clientId
):
null
);
//******* EDUARDO END **************//
clientsData
.
put
(
clientId
,
clientData
);
}
...
...
src/navigators/smart/tom/core/TOMLayer.java
浏览文件 @
7efcf90d
...
...
@@ -63,7 +63,6 @@ import navigators.smart.tom.core.timer.messages.RTMessage;
import
navigators.smart.tom.util.BatchBuilder
;
import
navigators.smart.tom.util.BatchReader
;
import
navigators.smart.tom.util.Logger
;
import
navigators.smart.tom.util.Storage
;
import
navigators.smart.tom.util.TOMUtil
;
...
...
@@ -356,7 +355,7 @@ public final class TOMLayer extends Thread implements RequestReceiver {
// return the batch
return
bb
.
createBatch
(
System
.
currentTimeMillis
(),
numberOfNonces
,
numberOfMessages
,
totalMessageSize
,
this
.
reconfManager
.
getStaticConf
().
getUseSignatures
()
==
1
,
messages
,
signatures
,
this
.
reconfManager
);
}
}
...
...
@@ -510,9 +509,8 @@ public final class TOMLayer extends Thread implements RequestReceiver {
* @return
*/
public
TOMMessage
[]
checkProposedValue
(
byte
[]
proposedValue
)
{
if
(
Logger
.
debug
)
{
Logger
.
println
(
"(TOMLayer.isProposedValueValid) starting"
);
}
BatchReader
batchReader
=
new
BatchReader
(
proposedValue
,
this
.
reconfManager
.
getStaticConf
().
getUseSignatures
()
==
1
);
...
...
src/navigators/smart/tom/util/SignatureTest.java
0 → 100644
浏览文件 @
7efcf90d
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
navigators.smart.tom.util
;
import
java.security.KeyPair
;
import
java.security.KeyPairGenerator
;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
import
java.security.Signature
;
/**
*
* @author alysson
*/
public
class
SignatureTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
byte
[]
data
=
new
byte
[
20
];
byte
[]
signature
;
Signature
signEng
;
long
start
,
end
;
KeyPairGenerator
kpg
=
KeyPairGenerator
.
getInstance
(
"RSA"
);
kpg
.
initialize
(
1024
);
KeyPair
kp
=
kpg
.
genKeyPair
();
PublicKey
publicKey
=
kp
.
getPublic
();
PrivateKey
privateKey
=
kp
.
getPrivate
();
signEng
=
Signature
.
getInstance
(
"SHA1withRSA"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
=
Signature
.
getInstance
(
"SHA1withRSA"
);
signEng
.
initSign
(
privateKey
);
}
start
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
=
Signature
.
getInstance
(
"SHA1withRSA"
);
signEng
.
initSign
(
privateKey
);
}
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"1000 init sign: "
+(
end
-
start
)+
"ms"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
.
update
(
data
);
signature
=
signEng
.
sign
();
}
start
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
.
update
(
data
);
signature
=
signEng
.
sign
();
}
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"1000 sign: "
+(
end
-
start
)+
"ms"
);
signEng
.
update
(
data
);
signature
=
signEng
.
sign
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
=
Signature
.
getInstance
(
"SHA1withRSA"
);
signEng
.
initVerify
(
publicKey
);
}
start
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
=
Signature
.
getInstance
(
"SHA1withRSA"
);
signEng
.
initVerify
(
publicKey
);
}
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"1000 init verify: "
+(
end
-
start
)+
"ms"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
.
update
(
data
);
signEng
.
verify
(
signature
);
}
start
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
signEng
.
update
(
data
);
signEng
.
verify
(
signature
);
}
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"1000 verify: "
+(
end
-
start
)+
"ms"
);
}
}
src/navigators/smart/tom/util/TOMUtil.java
浏览文件 @
7efcf90d
...
...
@@ -25,7 +25,9 @@ import java.io.ObjectOutputStream;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
import
java.security.Signature
;
import
java.security.SignatureException
;
import
java.util.Arrays
;
import
java.util.concurrent.Semaphore
;
import
java.util.concurrent.locks.ReentrantLock
;
import
navigators.smart.reconfiguration.ViewManager
;
...
...
@@ -80,13 +82,16 @@ public class TOMUtil {
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
return
null
;
}
return
bOut
.
toByteArray
();
}
public
static
Object
getObject
(
byte
[]
b
)
{
if
(
b
==
null
)
System
.
out
.
println
(
"O ARRAY E NULL!!!!"
);
if
(
b
==
null
)
return
null
;
ByteArrayInputStream
bInp
=
new
ByteArrayInputStream
(
b
);
try
{
ObjectInputStream
obInp
=
new
ObjectInputStream
(
bInp
);
...
...
@@ -95,7 +100,6 @@ public class TOMUtil {
bInp
.
close
();
return
ret
;
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
"Isto rebenta aqui!!"
);
ex
.
printStackTrace
();
return
null
;
}
...
...
@@ -111,6 +115,7 @@ public class TOMUtil {
*/
public
static
byte
[]
signMessage
(
PrivateKey
key
,
byte
[]
message
)
{
lock
.
lock
();
byte
[]
result
=
null
;
try
{
if
(
signatureEngine
==
null
)
{
signatureEngine
=
Signature
.
getInstance
(
"SHA1withRSA"
);
...
...
@@ -120,14 +125,13 @@ public class TOMUtil {
signatureEngine
.
update
(
message
);
byte
[]
result
=
signatureEngine
.
sign
();
lock
.
unlock
();
return
result
;
result
=
signatureEngine
.
sign
();
}
catch
(
Exception
e
)
{
lock
.
unlock
();
e
.
printStackTrace
();
return
null
;
}
lock
.
unlock
();
return
result
;
}
/**
...
...
@@ -136,10 +140,11 @@ public class TOMUtil {
* @param key the public key to be used to verify the signature
* @param message the signed message
* @param signature the signature to be verified
* @return t
he signatur
e
* @return t
rue if the signature is valid, false otherwis
e
*/
public
static
boolean
verifySignature
(
PublicKey
key
,
byte
[]
message
,
byte
[]
signature
)
{
lock
.
lock
();
boolean
result
=
false
;
//long startTime = System.nanoTime();
try
{
if
(
signatureEngine
==
null
)
{
...
...
@@ -148,9 +153,7 @@ public class TOMUtil {
signatureEngine
.
initVerify
(
key
);
signatureEngine
.
update
(
message
);
boolean
result
=
signatureEngine
.
verify
(
signature
);
result
=
verifySignature
(
signatureEngine
,
message
,
signature
);
/*
st.store(System.nanoTime()-startTime);
//statistics about signature execution time
...
...
@@ -166,14 +169,30 @@ public class TOMUtil {
count = 0;
st = new Storage(BENCHMARK_PERIOD);
}
*/
lock
.
unlock
();
return
result
;
*/
}
catch
(
Exception
e
)
{
lock
.
unlock
();
e
.
printStackTrace
();
return
false
;
}
lock
.
unlock
();
return
result
;
}
/**
* Verify the signature of a message.
*
* @param initializedSignatureEngine a signature engine already initialized
* for verification
* @param message the signed message
* @param signature the signature to be verified
* @return true if the signature is valid, false otherwise
*/
public
static
boolean
verifySignature
(
Signature
initializedSignatureEngine
,
byte
[]
message
,
byte
[]
signature
)
throws
SignatureException
{
//TODO: limit the amount of parallelization we can do to save some cores for other tasks
//maybe we can use a semaphore here initialized with the maximum number of parallel verifications:
//Semaphore sem = new Semaphore(10, true); then we can run sem.acquire() and sem.release()
initializedSignatureEngine
.
update
(
message
);
return
initializedSignatureEngine
.
verify
(
signature
);
}
public
static
String
byteArrayToString
(
byte
[]
b
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录