Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit e33d2e1e authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Merge pull request #142 in EDELIVERY/smp from...

Merge pull request #142 in EDELIVERY/smp from bugfix/EDELIVERY-4219-certificates-pem-with-n-r to development

* commit 'f1da196d5fcf0a2868a4705d11a08dc789e22aec':
  Remove bug causing double base64 encoding for new line terminator \n\r
  Update code for upload certificate for the user authentication.
parents 294a753e 9780edfd
No related branches found
No related tags found
No related merge requests found
......@@ -210,10 +210,7 @@ export class UserDetailsDialogComponent {
uploadCertificate(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = (e) => {
this.certificateService.uploadCertificate$(reader.result).subscribe((res: CertificateRo) => {
this.certificateService.uploadCertificate$(file).subscribe((res: CertificateRo) => {
if (res && res.certificateId){
this.userForm.patchValue({
'subject': res.subject,
......@@ -231,12 +228,7 @@ export class UserDetailsDialogComponent {
this.alertService.exception('Error uploading certificate file ' + file.name, err);
}
);
};
reader.onerror = (err) => {
this.alertService.exception('Error reading certificate file ' + file.name, err);
};
reader.readAsBinaryString(file);
}
onCertificateToggleChanged({checked}: MatSlideToggleChange) {
......
package eu.europa.ec.edelivery.smp.services.ui;
import eu.europa.ec.edelivery.smp.utils.BCryptPasswordHash;
import eu.europa.ec.edelivery.smp.data.dao.BaseDao;
import eu.europa.ec.edelivery.smp.data.dao.UserDao;
import eu.europa.ec.edelivery.smp.data.model.DBCertificate;
......@@ -15,6 +14,7 @@ import eu.europa.ec.edelivery.smp.exceptions.ErrorCode;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.logging.SMPLogger;
import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory;
import eu.europa.ec.edelivery.smp.utils.BCryptPasswordHash;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
......@@ -36,9 +36,9 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> {
private static final SMPLogger LOG = SMPLoggerFactory.getLogger(UIUserService.class);
private static final byte[] S_PEM_START_TAG = "-----BEGIN CERTIFICATE-----\n".getBytes();
private static final byte[] S_PEM_START_TAG = "-----BEGIN CERTIFICATE-----".getBytes();
private static final byte[] S_PEM_END_TAG = "\n-----END CERTIFICATE-----".getBytes();
private static final byte[] S_PEM_END_TAG = "-----END CERTIFICATE-----".getBytes();
private static final String S_BLUECOAT_DATEFORMAT ="MMM dd HH:mm:ss yyyy";
......@@ -160,7 +160,9 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> {
// try to encode
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(S_PEM_START_TAG);
bos.write('\n');
bos.write(Base64.getMimeEncoder().encode(certData));
bos.write('\n');
bos.write(S_PEM_END_TAG);
is = new ByteArrayInputStream(bos.toByteArray());
}
......
......@@ -38,7 +38,9 @@ public class X509CertificateToCertificateROConverterTest {
{"cert-escaped-chars.pem", "C=BE,O=DIGIT,OU=CEF,CN=Escape characters \\,\\\\#\\+\\<\\>\\\"\\=", "C=BE,O=DIGIT,OU=CEF,CN=Escape characters \\,\\\\#\\+\\<\\>\\\"\\=","5c1bb275","sno=5c1bb275&subject=C%3DBE%2CO%3DDIGIT%2COU%3DCEF%2CCN%3DEscape+characters+%5C%2C%5C%5C%23%5C%2B%5C%3C%5C%3E%5C%22%5C%3D&validfrom=Dec+20+16%3A17%3A09+2018+GMT&validto=Dec+17+16%3A17%3A09+2028+GMT&issuer=C%3DBE%2CO%3DDIGIT%2COU%3DCEF%2CCN%3DEscape+characters+%5C%2C%5C%5C%23%5C%2B%5C%3C%5C%3E%5C%22%5C%3D","CN=Escape characters \\,\\\\\\#\\+\\<\\>\\\"\\=,O=DIGIT,C=BE:000000005c1bb275"},
{"cert-nonAscii.pem", "C=BE,O=DIGIT,OU=CEF,CN=NonAscii chars: àøýßĉæãäħ", "C=BE,O=DIGIT,OU=CEF,CN=NonAscii chars: àøýßĉæãäħ","5c1bb38d","sno=5c1bb38d&subject=C%3DBE%2CO%3DDIGIT%2COU%3DCEF%2CCN%3DNonAscii+chars%3A++%C3%A0%C3%B8%C3%BD%C3%9F%C4%89%C3%A6%C3%A3%C3%A4%C4%A7&validfrom=Dec+20+16%3A21%3A49+2018+GMT&validto=Dec+17+16%3A21%3A49+2028+GMT&issuer=C%3DBE%2CO%3DDIGIT%2COU%3DCEF%2CCN%3DNonAscii+chars%3A++%C3%A0%C3%B8%C3%BD%C3%9F%C4%89%C3%A6%C3%A3%C3%A4%C4%A7","CN=NonAscii chars: àøýßĉæãäħ,O=DIGIT,C=BE:000000005c1bb38d"},
{"cert-with-email.pem", "C=BE,O=DIGIT,OU=CEF,CN=Cert with email", "C=BE,O=DIGIT,OU=CEF,CN=Cert with email","5c1bb358","sno=5c1bb358&subject=C%3DBE%2CO%3DDIGIT%2COU%3DCEF%2CCN%3DCert+with+email&validfrom=Dec+20+16%3A20%3A56+2018+GMT&validto=Dec+17+16%3A20%3A56+2028+GMT&issuer=C%3DBE%2CO%3DDIGIT%2COU%3DCEF%2CCN%3DCert+with+email","CN=Cert with email,O=DIGIT,C=BE:000000005c1bb358"},
};
{"cert-smime.pem", "CN=edelivery_sml,OU=PEPPOL TEST SMP,O=European Commission,C=BE", "C=BE,O=OpenPEPPOL AISBL,OU=FOR TEST ONLY,CN=PEPPOL SERVICE METADATA PUBLISHER TEST CA - G2","3cfe6b37e4702512c01e71f9b9175464","sno=3cfe6b37e4702512c01e71f9b9175464&subject=CN%3Dedelivery_sml%2COU%3DPEPPOL+TEST+SMP%2CO%3DEuropean+Commission%2CC%3DBE&validfrom=Sep+21+02%3A00%3A00+2018+GMT&validto=Sep+11+01%3A59%3A59+2020+GMT&issuer=C%3DBE%2CO%3DOpenPEPPOL+AISBL%2COU%3DFOR+TEST+ONLY%2CCN%3DPEPPOL+SERVICE+METADATA+PUBLISHER+TEST+CA+-+G2","CN=edelivery_sml,O=European Commission,C=BE:3cfe6b37e4702512c01e71f9b9175464"},
};
}
......
......@@ -337,6 +337,24 @@ public class UIUserServiceIntegrationTest extends AbstractServiceIntegrationTest
assertTrue(cer.getValidFrom().before(cer.getValidTo()));
}
@Test
public void testGetCertificateDataSMime() throws IOException, CertificateException {
// given
byte[] buff = IOUtils.toByteArray(UIUserServiceIntegrationTest.class.getResourceAsStream("/certificates/cert-smime.pem"));
// when
CertificateRO cer = testInstance.getCertificateData(buff);
//then
assertEquals("CN=edelivery_sml,O=European Commission,C=BE:3cfe6b37e4702512c01e71f9b9175464", cer.getCertificateId());
assertEquals("C=BE,O=OpenPEPPOL AISBL,OU=FOR TEST ONLY,CN=PEPPOL SERVICE METADATA PUBLISHER TEST CA - G2", cer.getIssuer());
assertEquals("CN=edelivery_sml,OU=PEPPOL TEST SMP,O=European Commission,C=BE", cer.getSubject());
assertEquals("3cfe6b37e4702512c01e71f9b9175464", cer.getSerialNumber());
assertNotNull(cer.getValidFrom());
assertNotNull(cer.getValidTo());
assertTrue(cer.getValidFrom().before(cer.getValidTo()));
}
@Test
public void testGetCertificateDataDER() throws IOException, CertificateException {
// given
......
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