Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Методы для аутенфикации при отсутствии прямого доступа к сертификату #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ fabric.properties

#jcp
jcp-*
/replay_pid85356.log
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>ru.kontur.diadoc</groupId>
<artifactId>diadocsdk</artifactId>
<version>3.20.0-dev.5296.26860</version>
<version>3.20.0-dev.5296.26860_spimex</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

теперь версионирование делается вручную по semever от версии в мастере, он убежал вперед


<packaging>jar</packaging>

Expand Down
56 changes: 51 additions & 5 deletions src/main/java/Diadoc/Api/auth/AuthenticateClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void authenticate(String login, String password) throws DiadocSdkExceptio

}

public void authenticate(X509Certificate currentCert, boolean autoConfirm) throws DiadocSdkException {
public byte[] authenticate(X509Certificate currentCert, boolean autoConfirm) throws DiadocSdkException {
try {
authManager.clearCredentials();

Expand All @@ -90,16 +90,37 @@ public void authenticate(X509Certificate currentCert, boolean autoConfirm) throw
String token = getDecryptedToken(response, currentCert);
confirmAuthenticationByCertificate(currentCert, token);
}
return response;
} catch (URISyntaxException | IOException | CertificateEncodingException | TokenDecryptException ex) {
throw new DiadocSdkException(ex);
}
}

public void authenticate(X509Certificate currentCert) throws DiadocSdkException {
authenticate(currentCert, true);
}

public void confirmAuthenticationByCertificate(X509Certificate currentCert, String token) throws DiadocSdkException {
public byte[] authenticate(byte[] currentCert) throws DiadocSdkException {
korvalanni marked this conversation as resolved.
Show resolved Hide resolved
try {
authManager.clearCredentials();

var request = RequestBuilder
.post(new URIBuilder(diadocHttpClient.getBaseUrl())
.setPath(V_3_AUTHENTICATE)
.addParameter("type", "certificate")
.build())
.addHeader("Content-Type", "application/octet-stream")
.setEntity(new ByteArrayEntity(currentCert));

var response = diadocHttpClient.performRequest(request);

return response;
} catch (URISyntaxException | IOException ex) {
throw new DiadocSdkException(ex);
}
}

public String confirmAuthenticationByCertificate(X509Certificate currentCert, String token) throws DiadocSdkException {
try {
var request = RequestBuilder.post(
new URIBuilder(diadocHttpClient.getBaseUrl())
Expand All @@ -109,12 +130,37 @@ public void confirmAuthenticationByCertificate(X509Certificate currentCert, Stri
.setEntity(new ByteArrayEntity(currentCert.getEncoded()));

var response = diadocHttpClient.performRequest(request);

authManager.setCredentials(StringUtils.newStringUtf8(response));

String authToken = StringUtils.newStringUtf8(response);

authManager.setCredentials(authToken);

return authToken;
} catch (URISyntaxException | CertificateEncodingException | IOException ex) {
throw new DiadocSdkException(ex);
}
}
public String confirmAuthenticationByCertificate(byte[] currentCert, String thumbprint, String token) throws DiadocSdkException {
try {
var uriBuilder = new URIBuilder(diadocHttpClient.getBaseUrl())
.setPath("/V3/AuthenticateConfirm")
.addParameter("token", token);
if (null != thumbprint)
uriBuilder.addParameter("thumbprint", thumbprint);
var request = RequestBuilder.post(
uriBuilder.build());
if (null != currentCert)
request.setEntity(new ByteArrayEntity(currentCert));

var response = diadocHttpClient.performRequest(request);

String authToken = StringUtils.newStringUtf8(response);
authManager.setCredentials(authToken);
return authToken;
} catch (URISyntaxException | IOException ex) {
throw new DiadocSdkException(ex);
}
}

private String getDecryptedToken(byte[] encryptedToken, X509Certificate currentCert) throws TokenDecryptException {
return StringUtils.newStringUtf8(Base64.encodeBase64(TokenDecryptManager.decryptToken(encryptedToken, currentCert)));
Expand Down