This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InMemoryRecord.java
133 lines (121 loc) · 3.95 KB
/
InMemoryRecord.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.github.glusk2.wse.core.db;
import java.math.BigInteger;
import java.nio.ByteOrder;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.sql.SQLException;
import java.util.Locale;
import com.github.glusk2.wse.common.crypto.srp6.SRP6FromBigIntRule;
import com.github.glusk2.wse.common.crypto.srp6.SRP6FromRawRule;
import com.github.glusk2.wse.common.crypto.srp6.SRP6Integer;
import com.github.glusk2.wse.common.crypto.srp6.SRP6PrecomputedValue;
import com.github.glusk2.wse.common.crypto.srp6.SRP6PrivateKey;
import com.github.glusk2.wse.common.crypto.srp6.SRP6Record;
import com.github.glusk2.wse.common.crypto.srp6.SRP6Verifier;
import com.github.glusk2.wse.common.crypto.util.hashing.ImdSimpleCopy;
import com.github.glusk2.wse.common.crypto.util.hashing.ImmutableMessageDigest;
@SuppressWarnings("checkstyle:parametername")
public final class InMemoryRecord implements SRP6Record {
private static final int HEX_RADIX = 16;
private static final int SHA1_LENGTH = 20;
private static final int DEFAULT_INT_LENGTH = 32;
private final SRP6Integer v;
private final SRP6Integer s;
@SuppressWarnings("checkstyle:membername")
private final SRP6Integer N;
private final SRP6Integer g;
public InMemoryRecord(
SRP6Integer N,
SRP6Integer g,
SRP6Integer s,
String I,
String P,
ImmutableMessageDigest imd
) {
this(
s,
new SRP6Verifier(
N,
g,
new SRP6PrivateKey(
imd,
s,
P,
I,
new SRP6FromRawRule(
SHA1_LENGTH,
ByteOrder.LITTLE_ENDIAN
)
),
new SRP6FromBigIntRule(
N.bytes().length,
ByteOrder.LITTLE_ENDIAN
)
),
N,
g
);
}
public InMemoryRecord(
SRP6Integer s,
SRP6Integer v,
SRP6Integer N,
SRP6Integer g
) {
this.s = s;
this.v = v;
this.N = N;
this.g = g;
}
@Override
public SRP6Integer verifier() throws SQLException {
return this.v;
}
@Override
public SRP6Integer salt() throws SQLException {
return this.s;
}
@Override
public SRP6Integer modulus() throws SQLException {
return this.N;
}
@Override
public SRP6Integer generator() throws SQLException {
return this.g;
}
public static void main(final String[] args) throws Exception {
String username = args[0].toUpperCase(Locale.US);
String password = args[1].toUpperCase(Locale.US);
SRP6Record acc =
new InMemoryRecord(
new SRP6PrecomputedValue(
new BigInteger(
("894B645E 89E1535B BDAD5B8B 29065053" +
"0801B18E BFBF5E8F AB3C8287 2A3E9BB7"
).replaceAll(" ", ""),
HEX_RADIX
)
),
new SRP6PrecomputedValue(
new BigInteger("7")
),
new SRP6PrecomputedValue(
new BigInteger(
1,
new SecureRandom().generateSeed(DEFAULT_INT_LENGTH)
)
),
username,
password,
new ImdSimpleCopy(MessageDigest.getInstance("SHA-1"))
);
System.out.format(
"Record:%n--------%nI: %s%nN: %s%ng: %s%nv: %s%ns: %s%n",
username,
acc.modulus().bigInteger().toString(HEX_RADIX),
acc.generator().bigInteger().toString(HEX_RADIX),
acc.verifier().bigInteger().toString(HEX_RADIX),
acc.salt().bigInteger().toString(HEX_RADIX)
);
}
}