Search in sources :

Example 1 with ProxyAuthenticateHeader

use of javax.sip.header.ProxyAuthenticateHeader in project XobotOS by xamarin.

the class AuthenticationHelperImpl method getAuthorization.

/**
     * Generates an authorisation header in response to wwwAuthHeader.
     *
     * @param method method of the request being authenticated
     * @param uri digest-uri
     * @param requestBody the body of the request.
     * @param authHeader the challenge that we should respond to
     * @param userCredentials username and pass
     *
     * @return an authorisation header in response to authHeader.
     *
     * @throws OperationFailedException if auth header was malformated.
     */
private AuthorizationHeader getAuthorization(String method, String uri, String requestBody, WWWAuthenticateHeader authHeader, UserCredentials userCredentials) {
    String response = null;
    // JvB: authHeader.getQop() is a quoted _list_ of qop values
    // (e.g. "auth,auth-int") Client is supposed to pick one
    String qopList = authHeader.getQop();
    String qop = (qopList != null) ? "auth" : null;
    String nc_value = "00000001";
    String cnonce = "xyz";
    response = MessageDigestAlgorithm.calculateResponse(authHeader.getAlgorithm(), userCredentials.getUserName(), authHeader.getRealm(), userCredentials.getPassword(), // JvB added
    authHeader.getNonce(), // JvB added
    nc_value, // JvB added
    cnonce, method, uri, requestBody, qop, // jvb changed
    sipStack.getStackLogger());
    AuthorizationHeader authorization = null;
    try {
        if (authHeader instanceof ProxyAuthenticateHeader) {
            authorization = headerFactory.createProxyAuthorizationHeader(authHeader.getScheme());
        } else {
            authorization = headerFactory.createAuthorizationHeader(authHeader.getScheme());
        }
        authorization.setUsername(userCredentials.getUserName());
        authorization.setRealm(authHeader.getRealm());
        authorization.setNonce(authHeader.getNonce());
        authorization.setParameter("uri", uri);
        authorization.setResponse(response);
        if (authHeader.getAlgorithm() != null) {
            authorization.setAlgorithm(authHeader.getAlgorithm());
        }
        if (authHeader.getOpaque() != null) {
            authorization.setOpaque(authHeader.getOpaque());
        }
        // jvb added
        if (qop != null) {
            authorization.setQop(qop);
            authorization.setCNonce(cnonce);
            authorization.setNonceCount(Integer.parseInt(nc_value));
        }
        authorization.setResponse(response);
    } catch (ParseException ex) {
        throw new RuntimeException("Failed to create an authorization header!");
    }
    return authorization;
}
Also used : ProxyAuthenticateHeader(javax.sip.header.ProxyAuthenticateHeader) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) ParseException(java.text.ParseException)

Example 2 with ProxyAuthenticateHeader

use of javax.sip.header.ProxyAuthenticateHeader in project XobotOS by xamarin.

the class AuthenticationHelperImpl method getAuthorization.

/**
     * Generates an authorisation header in response to wwwAuthHeader.
     *
     * @param method method of the request being authenticated
     * @param uri digest-uri
     * @param requestBody the body of the request.
     * @param authHeader the challenge that we should respond to
     * @param userCredentials username and pass
     *
     * @return an authorisation header in response to authHeader.
     *
     * @throws OperationFailedException if auth header was malformated.
     */
private AuthorizationHeader getAuthorization(String method, String uri, String requestBody, WWWAuthenticateHeader authHeader, UserCredentialHash userCredentials) {
    String response = null;
    // JvB: authHeader.getQop() is a quoted _list_ of qop values
    // (e.g. "auth,auth-int") Client is supposed to pick one
    String qopList = authHeader.getQop();
    String qop = (qopList != null) ? "auth" : null;
    String nc_value = "00000001";
    String cnonce = "xyz";
    response = MessageDigestAlgorithm.calculateResponse(authHeader.getAlgorithm(), // JvB added
    userCredentials.getHashUserDomainPassword(), // JvB added
    authHeader.getNonce(), // JvB added
    nc_value, // JvB added
    cnonce, method, uri, requestBody, qop, // jvb changed
    sipStack.getStackLogger());
    AuthorizationHeader authorization = null;
    try {
        if (authHeader instanceof ProxyAuthenticateHeader) {
            authorization = headerFactory.createProxyAuthorizationHeader(authHeader.getScheme());
        } else {
            authorization = headerFactory.createAuthorizationHeader(authHeader.getScheme());
        }
        authorization.setUsername(userCredentials.getUserName());
        authorization.setRealm(authHeader.getRealm());
        authorization.setNonce(authHeader.getNonce());
        authorization.setParameter("uri", uri);
        authorization.setResponse(response);
        if (authHeader.getAlgorithm() != null) {
            authorization.setAlgorithm(authHeader.getAlgorithm());
        }
        if (authHeader.getOpaque() != null) {
            authorization.setOpaque(authHeader.getOpaque());
        }
        // jvb added
        if (qop != null) {
            authorization.setQop(qop);
            authorization.setCNonce(cnonce);
            authorization.setNonceCount(Integer.parseInt(nc_value));
        }
        authorization.setResponse(response);
    } catch (ParseException ex) {
        throw new RuntimeException("Failed to create an authorization header!");
    }
    return authorization;
}
Also used : ProxyAuthenticateHeader(javax.sip.header.ProxyAuthenticateHeader) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)2 AuthorizationHeader (javax.sip.header.AuthorizationHeader)2 ProxyAuthenticateHeader (javax.sip.header.ProxyAuthenticateHeader)2 ProxyAuthorizationHeader (javax.sip.header.ProxyAuthorizationHeader)2