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

Mosip-34514 Fixed digital signature issue. #1366

Merged
merged 3 commits into from
Nov 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

Expand All @@ -35,7 +34,7 @@
* @author Manoj SP
* @author Sanjay Murali
*/
@Component

public abstract class BaseAuthFilter extends BaseIDAFilter {

private static final String SIGNATURE_HEADER = "signature header";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Dinesh Karuppiah.T
*/
@Component

public class DefaultAuthTypeFilter extends DefaultInternalFilter {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.Objects;
import java.util.stream.Collectors;

import org.springframework.stereotype.Component;

import io.mosip.authentication.core.constant.IdAuthCommonConstants;
import io.mosip.authentication.core.constant.IdAuthConfigKeyConstants;
import io.mosip.authentication.core.exception.IdAuthenticationAppException;
Expand All @@ -21,7 +19,7 @@
*
* @author Manoj SP
*/
@Component

public class DefaultInternalFilter extends InternalAuthFilter {

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
* @author Loganathan Sekar
* @author Nagarjuna K
*/
@Component

public abstract class IdAuthFilter extends BaseAuthFilter {

private static Logger mosipLogger = IdaLogger.getLogger(IdAuthFilter.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.mosip.authentication.common.service.filter;

import org.springframework.stereotype.Component;

@Component
public class InternalOtpFilter extends DefaultInternalFilter {

protected boolean needStoreAuthTransaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;

import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.JWSSigner;
import com.nimbusds.jose.crypto.MACSigner;
import com.nimbusds.jose.util.Base64URL;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;

@RunWith(SpringRunner.class)
public class KeyBindedTokenMatcherUtilTest {
Expand Down Expand Up @@ -84,23 +91,49 @@ public void matchTestWithInValidThumbprint_thenFail() {
}
}
@Test
public void matchTestWithInValidCerts_thenFail() throws IdAuthenticationBusinessException {
public void matchTestWithInValidCerts_thenFail() throws Exception {
ReflectionTestUtils.setField(keyBindedTokenMatcherUtil, "iatAdjSeconds", 30000000);
Map<String, Object> properties =new HashMap<>();
Map<String, String> bindingCertificates =new HashMap<>();
Map<String, String> input =new HashMap<>();
input.put("individualId","individualId");
input.put("type","type");
input.put("format","jwt");
input.put("token","eyJ0eXAiOiJKV1QiLCJ4NXQjUzI1NiI6IjBFSmtKMDYyWnZNZ0dKSk9BRVNYWFo1Tl9hamRDOG04Y0hPTXVKVVRGWUEiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2OTg5ODgyMTcsIm5iZiI6MTY5ODk4ODIxNywiZXhwIjoxNjk4OTg4ODIyLCJqdGkiOiJYZkpRaGVfU3RuNTNmaWc3YVV3V3MiLCJhdWQiOiJpZGEtYmluZGluZyIsInN1YiI6IjQxNTg2MTI2MDkiLCJpc3MiOiJwb3N0bWFuLWluamkifQ.bSqcJZlq5PyAExwPoww41OF-vBIyaADZ8OsXzA_7gtowNl0kChVAB11eIPEcjuFvYeQiSpQgNZsS2-w84ZBdiqh72kkJQLjN7ItMKNf-cekNRmG6XFf1os1vom7CwrguataoYvboiiXYw0WUfsZTmnhcOKC8XN3qAsB2YAyYEnBJBeKy5aCNAfJiOULTMrqAqcu-A1MA_wtAkaCJggiNxf1-5bJWjZYyQOkis0nHmbgWjzzThdd6TzMkLnUyNxzO2n1E9A19OJ2ZH0ZN1d46c8QBMsYmGX-Kz8B8GBDnDlwC4M5g4hmxuXCN6sBcVjAONl92LxI1htSZ6muv3xL1YQ");

input.put("token", generateTestJwtToken());
try {
keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties);
}catch (IdAuthenticationBusinessException e){
Assert.assertEquals("IDA-KBT-001",e.getErrorCode());
}
}

private String generateTestJwtToken() throws JOSEException {
// Secret key for signing - in production, this should be stored securely
String secretKey = "your-256-bit-secret-key-for-testing-purposes-only";
// Create HMAC signer
JWSSigner signer = new MACSigner(secretKey.getBytes());
// Create header with thumbprint
JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.HS256)
.x509CertSHA256Thumbprint(Base64URL.encode(Base64.getDecoder().decode("dGVzdF90aHVtYnByaW50"))) // "test_thumbprint" in base64
.build();
// Prepare JWT with claims
JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
.subject("test-user")
.issuer("test-issuer")
.claim("name", "Test User")
.claim("email", "[email protected]")
.claim("roles", "ROLE_USER")
.issueTime(new Date())
.expirationTime(new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000)) // 24 hours
.build();
// Create signed JWT with custom header
SignedJWT signedJWT = new SignedJWT(header, claimsSet);
// Sign the JWT
signedJWT.sign(signer);
// Serialize to compact form
return signedJWT.serialize();
}

@Test
public void matchTestWithValidCerts_thenFail() throws IdAuthenticationBusinessException {
ReflectionTestUtils.setField(keyBindedTokenMatcherUtil, "iatAdjSeconds", 300000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.Objects;
import java.util.stream.Collectors;

import org.springframework.stereotype.Component;

import io.mosip.authentication.common.service.filter.IdAuthFilter;
import io.mosip.authentication.common.service.filter.ResettableStreamHttpServletRequest;
import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants;
Expand All @@ -21,7 +19,7 @@
*
* @author Manoj SP
*/
@Component

public class OTPFilter extends IdAuthFilter {

/** The Constant AUTH. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import io.mosip.authentication.common.service.filter.IdAuthFilter;
import io.mosip.authentication.common.service.filter.ResettableStreamHttpServletRequest;
import io.mosip.authentication.core.constant.IdAuthCommonConstants;
Expand All @@ -21,7 +19,7 @@
*
* @author Mahammed Taheer
*/
@Component

public class IdentityKeyBindingFilter extends IdAuthFilter {

private static Logger mosipLogger = IdaLogger.getLogger(IdentityKeyBindingFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Component;

import io.mosip.authentication.common.service.filter.IdAuthFilter;
import io.mosip.authentication.common.service.filter.ResettableStreamHttpServletRequest;
import io.mosip.authentication.common.service.util.AuthTypeUtil;
Expand All @@ -25,7 +23,7 @@
*
* @author Mahammed Taheer
*/
@Component

public class KycAuthFilter extends IdAuthFilter {

private static Logger mosipLogger = IdaLogger.getLogger(KycAuthFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import io.mosip.authentication.common.service.filter.IdAuthFilter;
import io.mosip.authentication.common.service.filter.ResettableStreamHttpServletRequest;
import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants;
Expand All @@ -17,7 +15,7 @@
*
* @author Sanjay Murali
*/
@Component

public class KycAuthenticationFilter extends IdAuthFilter {

/** The Constant KYC. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import io.mosip.authentication.common.service.filter.IdAuthFilter;
import io.mosip.authentication.common.service.filter.ResettableStreamHttpServletRequest;
import io.mosip.authentication.core.constant.IdAuthCommonConstants;
Expand All @@ -21,7 +19,7 @@
*
* @author Mahammed Taheer
*/
@Component

public class KycExchangeFilter extends IdAuthFilter {

private static Logger mosipLogger = IdaLogger.getLogger(KycAuthFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author Mahammed Taheer
*/
@Component

public class VciExchangeFilter extends IdAuthFilter {

private static Logger mosipLogger = IdaLogger.getLogger(VciExchangeFilter.class);
Expand Down
Loading