-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from difi/hotfix-4.1.5
Hotfix 4.1.5
- Loading branch information
Showing
4 changed files
with
73 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/no/difi/oxalis/as4/outbound/BrowserTypeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package no.difi.oxalis.as4.outbound; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import lombok.extern.slf4j.Slf4j; | ||
import no.difi.oxalis.as4.inbound.OxalisAS4Version; | ||
import no.difi.oxalis.commons.util.OxalisVersion; | ||
import org.bouncycastle.asn1.x500.RDN; | ||
import org.bouncycastle.asn1.x500.X500Name; | ||
import org.bouncycastle.asn1.x500.style.BCStyle; | ||
import org.bouncycastle.asn1.x500.style.IETFUtils; | ||
import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder; | ||
|
||
import java.security.cert.CertificateEncodingException; | ||
import java.security.cert.X509Certificate; | ||
|
||
@Slf4j | ||
@Singleton | ||
public class BrowserTypeProvider { | ||
|
||
private final X509Certificate certificate; | ||
|
||
@Inject | ||
public BrowserTypeProvider(X509Certificate certificate) { | ||
this.certificate = certificate; | ||
} | ||
|
||
public String getBrowserType() { | ||
return String.format("Oxalis %s / AS4 %s / %s", | ||
OxalisVersion.getVersion(), | ||
OxalisAS4Version.getVersion(), | ||
getCN()); | ||
} | ||
|
||
private String getCN() { | ||
try { | ||
X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject(); | ||
RDN cn = x500name.getRDNs(BCStyle.CN)[0]; | ||
return IETFUtils.valueToString(cn.getFirst().getValue()); | ||
} catch (CertificateEncodingException e) { | ||
log.warn("Could not extract CN from certificate", e); | ||
return "Unknown"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters