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

Error for encrypt Data by using public key #58

Open
priyesh-shukla opened this issue Oct 17, 2020 · 2 comments
Open

Error for encrypt Data by using public key #58

priyesh-shukla opened this issue Oct 17, 2020 · 2 comments

Comments

@priyesh-shukla
Copy link

Hi,

I have started the webservice integration for Income Tax bulk ITR but i am not able to encrypt the data by using public key of income tax getting following error.

Fatal error: Uncaught Exception: Unknown key size for type "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"

@robrichards
Copy link
Owner

Make sure you are using the latest versions of xmlseclibs and wse-php. If you are still getting an error you will need to paste your code as the only time you should see that is if you are trying to generate a session key using the above key type - which is incompatible.

@priyesh-shukla
Copy link
Author

Hi Please see my code below I am not able to sign soap request;
`function finalSubmitITR(){
$login = 'ERIA101854';
$password = 'QWERTY@1';
$xmlFile = $_POST['itrxml'];
$doc = new DOMDocument();
$doc->load($xmlFile);
// Create a new Security object
$objDSig = new XMLSecurityDSig();
// Use the c14n exclusive canonicalization
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
// Sign using SHA-256
$objDSig->addReference(
$doc, XMLSecurityDSig::SHA256,
array('http://www.w3.org/2000/09/xmldsig#enveloped-signature')
);

// Create a new (private) Security key
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private'));

//If key has a passphrase, set it using
$objKey->passphrase = 'myitr1234';

// Load the private key
$objKey->loadKey('./app/controllers/myitr-privatekey.pem', TRUE);

// Sign the XML file
$objDSig->sign($objKey);
$tout = ('./app/controllers/myitr-privatekey.pem');
// Add the associated public key to the signature
$objDSig->add509Cert(file_get_contents($tout));

// Append the signature to the XML
$objDSig->appendSignature($doc->documentElement);
// Save the signed XML

/* $siteKey = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP_MGF1P, array('type' => 'public'));
$siteKey->loadKey('./app/controllers/EfilingDSC.cer', true, true);

    $options = array("KeyInfo" => array("X509SubjectKeyIdentifier" => true));
    $objWSSE->encryptSoapDoc($siteKey, $objKey, $options);

    $retVal = parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version);

    $doc = new DOMDocument();
    $doc->loadXML($retVal);

    $options = array("keys" => array("private" => array("key" => PRIVATE_KEY, "isFile" => true, "isCert" => false)));
    $objWSSE->decryptSoapDoc($doc, $options);*/
$doc->save($xmlFile);
$zipFileName = str_replace('.xml','',$xmlFile);
        $zipArchive = new ZipArchive();  
        if ($zipArchive->open($zipFileName.'.zip', (ZipArchive::CREATE | ZipArchive::OVERWRITE)) !== true)
            die("Failed to create archive\n");
        $zipArchive->addGlob($xmlFile);
        if ($zipArchive->status != ZIPARCHIVE::ER_OK)
            echo "Failed to write files to zip\n";
        $zipArchive->close();
        
ini_set("soap.wsdl_cache_enabled", "1");
$wsdl = 'https://services.incometaxindiaefiling.gov.in/e-FilingSecWS/ditsecws/BulkItrService?wsdl';
$client = new SoapClient($wsdl, array( 
        "cache_wsdl"=>WSDL_CACHE_NONE,
        "soap_version" => SOAP_1_1,
        'trace' => 1,
        'encoding' => 'UTF-8'
    )
);

$client->__setSoapHeaders([new WsseAuthHeader($login, $password)]);
$requestId = "ERIA101854-".rand(100000,999999);
$codif = file_get_contents( $zipFileName.'.zip');

$xml_base64 = base64_encode($codif);

//$request = array('DitRequest' => array('_' => '', 'uniqueRequestId'=>$requestId, 'dataHandler' => $xml_base64));
$request = '
<soapenv:Envelope xmlns:soapenv="https://schemas.xmlsoap.org/soap/envelope/"
xmlns:dit="https://incometaxindiaefiling.gov.in/ditsecws"
xmlns:req="https://incometaxindiaefiling.gov.in/ditsecws/request">
soapenv:Header/
soapenv:Body
dit:uploadBulkItr
<dit:DitRequest uniqueRequestId="ERIA101854-227795">
req:dataHandlerVUVzREJCUUFBQUFJQVBkWU1GSGpTYlVUMkFZQUFLQVhBQUJLQUFBQVlYQndMM1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y90SDBwOVNxbzV0WDhoYzJnNU1PcHVxQVFiVkFrcnYyWjc1UmpxRWlDSWx6OFVLWUVNRFZDY3lxL05qdjV6K3FCOVI5UVN3RUNGQU1VQUFBQUNBRDNXREJSNDBtMUU5Z0dBQUNnRndBQVNnQUFBQUFBQUFBQUFBQUF0b0VBQUFBQVlYQndMM1Z3Ykc5aFpITXZVSEpwZVdWemFDQlRhSFZyYkdFdmVHMXNMekUyTFRBNUxUSXdNakF2UjBsUVVGTXlOelkxUzE5SlZGSXRNVjh5TURJd1gwNWZPRGMwTVM1NGJXeFFTd1VHQUFBQUFBRUFBUUI0QUFBQVFBY0FBQUFB</req:dataHandler>
</dit:DitRequest>
</dit:uploadBulkItr>
</soapenv:Body>
</soapenv:Envelope>';

echo $request = soapRequestXml($request);
return;
//$request = array('DitRequest' => array('_' => '', 'uniqueRequestId'=>$requestId, 'dataHandler' => $xml_base64));
// $results = $client->__soapCall('uploadBulkItr', array($request));

try
{
$results = $client->uploadBulkItr($request);
}
catch(Exception $e)
{
// error handling goes here
// $sta = base64_decode($results);
echo "

REQUEST:\n" . $client->__getLastRequest() . "

";
echo "RESPONSE:\n" . $client->__getLastResponse() . "

";
echo "RESPONSE HEADERS:\n" . $client->__getLastResponseHeaders() . "

";
die("Error: ". $e->getMessage()."\n");
}
// $results = $client->uploadBulkItr($param1,$request);
$sta = base64_decode($results);
echo "

REQUEST:\n" . $client->__getLastRequest() . "

";
// echo "REQUEST HEADERS:\n" . $client->__getLastRequestHeaders() . "

";
// echo "RESPONSE:\n" . $client->__getLastResponse() . "

";
echo "RESPONSE HEADERS:\n" . $client->__getLastResponseHeaders() . "

";
// echo "Var Dump: "; var_dump($results);
//print_r($results);
// it;
echo "guruji";
}

function soapRequestXml($request){
$doc = new DOMDocument('1.0');
$doc->loadXML($request);
$objWSSE = new WSSESoap($doc);
$objWSSE->addTimestamp();
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'private'));
$objKey->loadKey('./app/controllers/private-key.pem', true);
$options = array("insertBefore" => false);
$objWSSE->signSoapDoc($objKey, $options);
$token = $objWSSE->addBinaryToken(file_get_contents('./app/controllers/incometax.pem'));
$objWSSE->attachTokentoSig($token);
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP_MGF1P, array('type' => 'public'));
$objKey->generateSessionKey();
$options = array("KeyInfo" => array("X509SubjectKeyIdentifier" => true));
$objWSSE->encryptSoapDoc($objKey, $options);
$doc = new DOMDocument();
$doc->loadXML($retVal);
$options = array("keys" => array("private" => array("key" => './app/controllers/private-key.pem', "isFile" => true, "isCert" => false)));
$objWSSE->decryptSoapDoc($doc, $options);
return $doc->saveXML();
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants