function Sign(){ try{ habilitaBoton(false); var pkcs12=document.firmaForm.certificado.value; var passwd=document.firmaForm.password.value; if(pkcs12 == "") { alert("Por favor seleccione un archivo .p12 o .pfx o .cer"); habilitaBoton(true); return; } if(passwd == "") { alert("Debe capturar la contraseña correcta"); habilitaBoton(true); return; } var contenido = document.applet_secuencia.obtenSecuencial(document.firmaForm.siteId.name, document.firmaForm.siteId.value, document.location); document.firmaForm.password.value=""; var pkcs7=""; if(contenido=="70"){ alert("Este sitio no tiene permiso para montar los servicios del IMSS."); habilitaBoton(true); return; } if(contenido.length==2 || contenido.length==1){ alert("Error al contactar al servidor"); habilitaBoton(true); return; } if(pkcs12.indexOf(".cer") != -1 ) { pkcs7 = SignSat(contenido, pkcs12, passwd); } else if(pkcs12.indexOf(".p12") != -1 || pkcs12.indexOf(".pfx") != -1 ) { pkcs7 = SignIMSS(contenido, pkcs12, passwd); if(pkcs7 == "") { return; } } else { alert("El certificado no corresponde al formato validado."); habilitaBoton(true); return; } if(pkcs7 != "") { document.firmaForm.pkcs7.value = pkcs7; document.firmaForm.submit(); } } catch(error){ if (error.description){ alert("Ocurrió un error al iniciar sesión: " + error.description + ". Por favor, póngase en contacto con personal técnico del IMSS."); } else{ alert("Favor de verificar la configuración de su navegador para ingresar a IDSE " + "o descargue y ejecute la configuración automática. "); } habilitaBoton(true); return; } } function seleccionaCert(valor) { if(valor.indexOf(".cer") != -1 ) { document.firmaForm.llave.disabled = false; document.firmaForm.idUsuario.disabled = true; document.firmaForm.llave.style.background = "#FFFFFF"; document.firmaForm.idUsuario.style.background = "#CCCCCC"; } else { document.firmaForm.llave.disabled = true; document.firmaForm.idUsuario.disabled = false; document.firmaForm.idUsuario.style.background = "#FFFFFF"; document.firmaForm.llave.style.background = "#CCCCCC"; } } function SignSat(contenido, pkcs12, passwd) { var pkcs7 = ""; var keyPath = document.firmaForm.llave.value; if (contenido != ""){ pkcs7 = document.applet_ssign.firma(keyPath, pkcs12, passwd, contenido, "SHA1withRSA", 2); if(pkcs7.indexOf("Error")==-1){ //jcbg - actualizacion de codigo if( document.applet_ssign.getIsEmptyMessage() == true ){ window.alert( "El mensaje no tiene contenido" ); } else { return pkcs7; } // return pkcs7; } else{ habilitaBoton(true); procesaExcepcionSAT(pkcs7); return ""; } } else { alert("Error al contactar al servidor"); habilitaBoton(true); return ""; } return pkcs7; } function procesaExcepcionSAT(exc){ var msg = exc; /** ERROR EN EL ARCHIVO *.key */ if ( exc.indexOf( "java.io.IOException: DER input, Integer tag error" ) != -1 ) { if(( document.firmaForm.llave.value.indexOf(".key") != -1 ) ) { msg = "El archivo de llave privada está corrupto o no es procesable"; } else { msg = "El archivo seleccionado para la llave privada no corresponde al formato"; } } /** MENSAJE DE ERROR EN EL ARCHIVO *.cer */ if ( exc.indexOf( "java.security.cert.CertificateException: Unable to initialize, "+ "java.io.IOException: DerInputStream.getLength(): lengthTag=127, too big.") != -1 ) { if( ( document.firmaForm.certificado.value.indexOf(".cer") != -1 ) ) { msg = "El archivo del certificado está corrupto o no es procesable"; } else { msg = "El archivo seleccionado para el certificado no corresponde al formato"; } } /** MENSAJE DE ERROR EN EL ARCHIVO *.cer */ if ( exc.indexOf( "java.io.IOException: DER input, Integer tag error" ) != -1 ) { if( ( document.firmaForm.certificado.value.indexOf(".cer") != -1 ) ) { msg = "El archivo del certificado está corrupto o no es procesable"; } else { msg = "Por favor seleccione un archivo .cer"; } } /** Mensaje de contraseña incorrecta */ if ( exc.indexOf( "java.io.IOException: failed to decrypt safe contents entry" ) != -1 ){ msg = " La contraseña no es correcta, intente de nuevo "; } /** Mensaje de ruta de archivo inválida */ if (exc.indexOf("java.io.FileNotFoundException") != -1 ) { msg = " La ruta " + exc.substr(55, exc.length-99) + " no es válida "; } alert( msg ); } function SignIMSS(contenido, pkcs12, passwd){ var pkcs7 = ""; if (contenido != ""){ pkcs7 = document.applet_firma.firma(pkcs12, passwd, contenido, "SHA1withRSA", 2); if(pkcs7.indexOf("Se produjo una excepcion")==-1){ return pkcs7; } else{ procesa_excepcion(pkcs7); habilitaBoton(true); return ""; } } else{ alert("Error al contactar al servidor"); habilitaBoton(true); } return pkcs7; } function procesa_excepcion(exc){ var msg = exc; if (exc.indexOf("java.io.IOException: DER input, Integer tag error") != -1 ){ if(( document.firmaForm.certificado.value.indexOf(".pfx") != -1 ) || (document.firmaForm.certificado.value.indexOf(".p12") != -1) ){ msg = "El archivo PKCS12 está corrupto"; } else{ msg = "Por favor seleccione un archivo .p12 o .pfx"; } } if (exc.indexOf("java.io.IOException: failed to decrypt safe contents entry") != -1){ msg = " La contraseña no es correcta, intente de nuevo "; } if (exc.indexOf("java.io.FileNotFoundException") != -1 ){ msg = " El archivo no existe o se modificó la ruta del archivo. Por favor verifique y actualice la información "; } alert(msg); } function habilitaBoton(habilitado){ if(habilitado) { document.firmaForm.password.disabled = false; document.getElementById("imgCargando").style.display = "none"; document.getElementById("tablaLogin").style.display = "inline"; } else { document.firmaForm.password.disabled = true; document.getElementById("imgCargando").style.display = "inline"; document.getElementById("tablaLogin").style.display = "none"; } }