Skip to content
Snippets Groups Projects
Commit f38a784b authored by Felix Sidokhine's avatar Felix Sidokhine
Browse files

wip

parent af97af56
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@ import net.jami.jams.common.objects.user.AccessLevel;
import net.jami.jams.common.objects.user.User;
import net.jami.jams.common.utils.LibraryLoader;
import net.jami.jams.common.utils.X509Utils;
import org.bouncycastle.cert.X509CRLHolder;
import java.io.File;
import java.io.FileInputStream;
......@@ -160,8 +161,29 @@ public class UserAuthenticationModule implements AuthenticationModule {
}
@Override
public AuthTokenResponse authenticateUser(X509Certificate[] certificates) {
return null;
public AuthTokenResponse authenticateUser(X509Certificate[] certificates, X509CRLHolder crl,
X509Certificate ca) {
//Extract the username for the certificate and verify that it is not revoked.
X509Certificate clientCert = certificates[0];
try {
//Check if the certificate is even valid.
clientCert.checkValidity();
//Check if the certificate was provided by a valid authority.
clientCert.verify(ca.getPublicKey());
//Here we need to make a request to the CRL to find out if it has been revoked.
if(crl.getRevokedCertificate(clientCert.getSerialNumber()) != null) return null;
//If the above cases have passed, then this user is indded valid.
//This is yet to be confirmed.
String username = clientCert.getSubjectDN().getName();
StatementList statementList = new StatementList();
StatementElement statementElement = new StatementElement("username","=",username,"");
statementList.addStatement(statementElement);
User user = datastore.getUserDao().getObjects(statementList).get(0);
return tokenController.getToken(user);
}
catch (Exception e){
return null;
}
}
@Override
......
openssl req -x509 -newkey rsa:4096 -days 3650 -nodes -keyout user.key -out user.crt -subj "/CN=fsidokhine"
openssl pkcs12 -export -out user.pfx -inkey user.key -in user.crt
curl -d -k -v -X POST "https://localhost:8080/api/auth/login" -E user.pfx --pass abc123
import json
import requests
baseUri = "https://localhost:8080"
data = {}
data['username'] = "admin"
data['password'] = "abc123"
......@@ -8,7 +10,7 @@ data['password'] = "abc123"
header = {}
header['Content-type'] = "application/json"
response = requests.put('http://localhost:8080/api/install/start',data=json.dumps(data),headers=header)
response = requests.put(baseUri + '/api/install/start',data=json.dumps(data),headers=header,verify=False)
if response.status_code == 200:
print("Succesfully created the administrative user!")
token = json.loads(response.text)['access_token']
......@@ -24,7 +26,7 @@ data['fields']['commonName'] = "TEST CA"
data['fields']['country'] = "FR"
data['fields']['lifetime'] = 10000000
response = requests.post('http://localhost:8080/api/install/ca',data=json.dumps(data),headers=header)
response = requests.post(baseUri + '/api/install/ca',data=json.dumps(data),headers=header,verify=False)
if response.status_code == 200:
print("Added CA parameters!")
else:
......@@ -52,7 +54,7 @@ data['ldapSettings']['fieldMappings']['facsimileTelephoneNumber'] = "FaxNumber"
data['ldapSettings']['fieldMappings']['extensionName'] = "PhoneNumberExtension"
data['ldapSettings']['fieldMappings']['o'] = "Organization"
response = requests.post('http://localhost:8080/api/install/auth',data=json.dumps(data),headers=header)
response = requests.post(baseUri + '/api/install/auth',data=json.dumps(data),headers=header,verify=False)
if response.status_code == 200:
print("Added LDAP parameters!")
else:
......@@ -65,12 +67,12 @@ data['crlLifetime'] = 100000
data['userLifetime'] = 100000
data['deviceLifetime'] = 100000
response = requests.post('http://localhost:8080/api/install/settings',data=json.dumps(data),headers=header)
response = requests.post(baseUri + '/api/install/settings',data=json.dumps(data),headers=header,verify=False)
#This completes the install, now we'll try to enroll.
data = {}
response = requests.post('http://localhost:8080/api/auth/login',data={"username":"fsidokhine","password":"mes87hesm97daa"})
response = requests.post(baseUri + '/api/auth/login',data={"username":"fsidokhine","password":"mes87hesm97daa"},verify=False)
if response.status_code == 200:
token = json.loads(response.text)['access_token']
......@@ -110,31 +112,31 @@ oTBLLnRmdyi/SFreL5WRhMm67DHne08LCqnkzEVwMIUECN5f2mkx9KP3BrsXuH2W
sxMmX+s/PapsdSyUJ2g3hAf6Iv5m0pcUeQ==
-----END NEW CERTIFICATE REQUEST-----'''
response = requests.post('http://localhost:8080/api/auth/device',headers=header,data=json.dumps(data))
response = requests.post(baseUri + '/api/auth/device',headers=header,data=json.dumps(data),verify=False)
print(response.status_code)
print(response.text)
print(token)
response = requests.get("http://localhost:8080/api/nameserver/name/aberaud",headers=header)
response = requests.get("http://localhost:8080/api/nameserver/name/aberaud",headers=header,verify=False)
print(response.status_code)
print(response.text)
response = requests.get("http://localhost:8080//api/auth/directories",headers=header)
response = requests.get("http://localhost:8080//api/auth/directories",headers=header,verify=False)
print(response.status_code)
print(response.text)
response = requests.get("http://localhost:8080/api/auth/user",headers=header)
response = requests.get("http://localhost:8080/api/auth/user",headers=header,verify=False)
print(response.status_code)
print(response.text)
print("Getting user profile as vcard")
response = requests.get("http://localhost:8080/api/auth/directory/entry?username=aberaud&format=vcard",headers=header)
response = requests.get("http://localhost:8080/api/auth/directory/entry?username=aberaud&format=vcard",headers=header,verify=False)
print(response.status_code)
print(response.text)
response = requests.post("http://localhost:8080/api/update",headers=header)
response = requests.post("http://localhost:8080/api/update",headers=header,verify=False)
print(response.status_code)
print(response.text)
-----BEGIN CERTIFICATE-----
MIIFCzCCAvOgAwIBAgIUFmkFCfLO2IiOp5zMv8saqdIGtbQwDQYJKoZIhvcNAQEL
BQAwFTETMBEGA1UEAwwKZnNpZG9raGluZTAeFw0yMDA1MzExNTIzNDNaFw0zMDA1
MjkxNTIzNDNaMBUxEzARBgNVBAMMCmZzaWRva2hpbmUwggIiMA0GCSqGSIb3DQEB
AQUAA4ICDwAwggIKAoICAQDVTpTBD/cyq/1qP+RSTw6blyYWmkqsdeMOvCJHAFrf
mFhgD7cKZSGxjtsdpCgB2yFxqT11yo0uLzCSz24HYmb7ZsAVgh4PvqPVeyxIHdig
fS79xT8nKZY+tUuZPt7A402fMqMf+E9P+NxdvPErL9yTtuHSx3uWXjsGGRI8BUr/
W6W5Mrr9xbYaa17GeBLExGCTm3pfPsIy4TugLItxDKYGRx1Es6NBNsdBrICJDRaG
2jNARXD5r8WBsc9GSOEuBF+LAb85eDXjV38DWHGN3eMt3Bqa6kisK2TU+P2ub8L2
hsstEpNyxW+MC90q3cKDpZF+EA3VzNOlRxXSfNSbDQ2Ljrp9cl/PKy2zUMCApriO
GeGFkfWD8JqUdjY/cuBE6Ow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aRvnmvAeKODeJ2Sdc8pn26NUH/M8hF0TPkASBGnf2wo
J6XcvcFLa6USB7hVX887JJgeFQCkQqyRdWmyVTio+xz4xj0w43CRKYvyn1PUYe4m
6aIeoWpTJNW1E4sjnz7eu5ojhoYLLx2t
-----END PRIVATE KEY-----
File added
......@@ -26,6 +26,7 @@ import net.jami.jams.common.authentication.AuthenticationSource;
import net.jami.jams.common.authentication.AuthenticationSourceType;
import net.jami.jams.common.jami.NameServer;
import net.jami.jams.common.objects.user.User;
import org.bouncycastle.cert.X509CRLHolder;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPublicKey;
......@@ -35,7 +36,7 @@ public interface AuthenticationModule {
void attachAuthSource(AuthenticationSourceType type, String settings);
AuthTokenResponse authenticateUser(String username, String password);
AuthTokenResponse authenticateUser(X509Certificate[] certificates);
AuthTokenResponse authenticateUser(X509Certificate[] certificates, X509CRLHolder crl, X509Certificate ca);
ConcurrentHashMap<AuthModuleKey, AuthenticationSource> getAuthSources();
boolean testModuleConfiguration(AuthenticationSourceType type, String configuration);
boolean createUser(AuthenticationSourceType type, String realm, NameServer nameServer, User user);
......
......@@ -26,13 +26,15 @@ import net.jami.jams.common.authmodule.AuthTokenResponse;
import java.security.cert.X509Certificate;
import static net.jami.jams.server.Server.certificateAuthority;
import static net.jami.jams.server.Server.userAuthenticationModule;
public class AuthRequestProcessor {
//This case does not talk to the authentication module, only to the ca
public static AuthTokenResponse processX509Auth(X509Certificate[] certificates){
return userAuthenticationModule.authenticateUser(certificates);
return userAuthenticationModule.authenticateUser(certificates,certificateAuthority.getLatestCRL().get(),
certificateAuthority.getCA());
}
public static AuthTokenResponse processUsernamePasswordAuth(String username, String password){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment