@@ -368,9 +368,177 @@ public void testWolfSignInteropVerify()
368368 boolean verified = verifier .verify (signature );
369369
370370 if (verified != true ) {
371+ /* Collect comprehensive diagnostic information for debugging */
372+ StringBuilder diagnostics = new StringBuilder ();
373+
374+ /* Environment Information */
375+ diagnostics .append ("Java Version: " )
376+ .append (System .getProperty ("java.version" )).append ("\n " );
377+ diagnostics .append ("Java Vendor: " )
378+ .append (System .getProperty ("java.vendor" )).append ("\n " );
379+ diagnostics .append ("Java Runtime: " )
380+ .append (System .getProperty ("java.runtime.name" ))
381+ .append ("\n " );
382+ diagnostics .append ("OS: " )
383+ .append (System .getProperty ("os.name" )).append (" " )
384+ .append (System .getProperty ("os.version" )).append (" " )
385+ .append (System .getProperty ("os.arch" )).append ("\n " );
386+
387+ /* Test Details */
388+ diagnostics .append ("Algorithm: " )
389+ .append (enabledAlgos .get (i )).append ("\n " );
390+ diagnostics .append ("Test Message: \" " )
391+ .append (toSign ).append ("\" \n " );
392+ diagnostics .append ("Test Message Bytes (hex): " )
393+ .append (bytesToHex (toSignBuf , 0 , toSignBuf .length ))
394+ .append ("\n " );
395+
396+ /* Provider Information */
397+ diagnostics .append ("Signer Provider: " )
398+ .append (signer .getProvider ().getName ())
399+ .append (" v" ).append (signer .getProvider ().getVersion ())
400+ .append ("\n " );
401+ diagnostics .append ("Signer Provider Info: " )
402+ .append (signer .getProvider ().getInfo ()).append ("\n " );
403+ diagnostics .append ("Verifier Provider: " )
404+ .append (verifier .getProvider ().getName ())
405+ .append (" v" ).append (verifier .getProvider ().getVersion ())
406+ .append ("\n " );
407+ diagnostics .append ("Verifier Provider Info: " )
408+ .append (verifier .getProvider ().getInfo ()).append ("\n " );
409+
410+ /* Key Information */
411+ diagnostics .append ("Private Key Algorithm: " )
412+ .append (priv .getAlgorithm ()).append ("\n " );
413+ diagnostics .append ("Private Key Format: " )
414+ .append (priv .getFormat ()).append ("\n " );
415+ diagnostics .append ("Public Key Algorithm: " )
416+ .append (pub .getAlgorithm ()).append ("\n " );
417+ diagnostics .append ("Public Key Format: " )
418+ .append (pub .getFormat ()).append ("\n " );
419+
420+ /* ECC Specific Information */
421+ if (priv instanceof java .security .interfaces .ECPrivateKey ) {
422+ java .security .interfaces .ECPrivateKey ecPriv =
423+ (java .security .interfaces .ECPrivateKey ) priv ;
424+ java .security .interfaces .ECPublicKey ecPub =
425+ (java .security .interfaces .ECPublicKey ) pub ;
426+
427+ diagnostics .append ("EC Curve: " )
428+ .append (ecPriv .getParams ().getCurve ()).append ("\n " );
429+ diagnostics .append ("EC Field Size: " )
430+ .append (ecPriv .getParams ().getCurve ().getField ()
431+ .getFieldSize ()).append ("\n " );
432+ diagnostics .append ("EC Order: " )
433+ .append (ecPriv .getParams ().getOrder ()).append ("\n " );
434+ diagnostics .append ("EC Cofactor: " )
435+ .append (ecPriv .getParams ().getCofactor ()).append ("\n " );
436+
437+ /* Try to determine curve name for reproduction */
438+ try {
439+ java .security .spec .ECParameterSpec params =
440+ ecPriv .getParams ();
441+ if (params .getCurve ().getField ()
442+ .getFieldSize () == 256 ) {
443+ diagnostics .append (
444+ "Likely Curve Name: secp256r1/prime256v1\n " );
445+ } else if (params .getCurve ().getField ()
446+ .getFieldSize () == 384 ) {
447+ diagnostics .append (
448+ "Likely Curve Name: secp384r1\n " );
449+ } else if (params .getCurve ().getField ()
450+ .getFieldSize () == 521 ) {
451+ diagnostics .append (
452+ "Likely Curve Name: secp521r1\n " );
453+ }
454+ } catch (Exception e ) {
455+ diagnostics .append ("Could not determine curve name\n " );
456+ }
457+
458+ /* Private key S value (full key for test reproduction) */
459+ byte [] sBytes = ecPriv .getS ().toByteArray ();
460+ diagnostics .append ("Private Key S (full): " )
461+ .append (bytesToHex (sBytes , 0 , sBytes .length ))
462+ .append ("\n " );
463+ diagnostics .append ("Private Key S (decimal): " )
464+ .append (ecPriv .getS ().toString ()).append ("\n " );
465+
466+ /* Public key point (full coordinates for test repro) */
467+ diagnostics .append ("Public Key X (hex): " )
468+ .append (ecPub .getW ().getAffineX ().toString (16 ))
469+ .append ("\n " );
470+ diagnostics .append ("Public Key Y (hex): " )
471+ .append (ecPub .getW ().getAffineY ().toString (16 ))
472+ .append ("\n " );
473+ diagnostics .append ("Public Key X (decimal): " )
474+ .append (ecPub .getW ().getAffineX ().toString ())
475+ .append ("\n " );
476+ diagnostics .append ("Public Key Y (decimal): " )
477+ .append (ecPub .getW ().getAffineY ().toString ())
478+ .append ("\n " );
479+
480+ /* Key encoding for complete reproduction */
481+ if (priv .getEncoded () != null ) {
482+ diagnostics .append ("Private Key Encoded (hex): " )
483+ .append (bytesToHex (priv .getEncoded (), 0 ,
484+ priv .getEncoded ().length ))
485+ .append ("\n " );
486+ }
487+ if (pub .getEncoded () != null ) {
488+ diagnostics .append ("Public Key Encoded (hex): " )
489+ .append (bytesToHex (pub .getEncoded (), 0 ,
490+ pub .getEncoded ().length ))
491+ .append ("\n " );
492+ }
493+ }
494+
495+ /* Signature Information */
496+ diagnostics .append ("Signature Length: " )
497+ .append (signature .length ).append (" bytes\n " );
498+ diagnostics .append ("Signature (hex): " )
499+ .append (bytesToHex (signature , 0 , signature .length ))
500+ .append ("\n " );
501+
502+ /* ASN.1 Analysis */
503+ if (signature .length > 6 && signature [0 ] == 0x30 ) {
504+ diagnostics .append ("ASN.1 SEQUENCE Length: " )
505+ .append (signature [1 ] & 0xFF ).append ("\n " );
506+ if (signature [2 ] == 0x02 ) {
507+ int rLen = signature [3 ] & 0xFF ;
508+ diagnostics .append ("ASN.1 R Length: " )
509+ .append (rLen ).append ("\n " );
510+ if (4 + rLen < signature .length &&
511+ signature [4 + rLen ] == 0x02 ) {
512+ int sLen = signature [5 + rLen ] & 0xFF ;
513+ diagnostics .append ("ASN.1 S Length: " )
514+ .append (sLen ).append ("\n " );
515+ }
516+ }
517+ }
518+
519+ /* Timing and Thread Information */
520+ diagnostics .append ("Failure Timestamp: " )
521+ .append (System .currentTimeMillis ()).append ("\n " );
522+ diagnostics .append ("Thread ID: " )
523+ .append (Thread .currentThread ().getId ()).append ("\n " );
524+ diagnostics .append ("Thread Name: " )
525+ .append (Thread .currentThread ().getName ()).append ("\n " );
526+
527+ /* All Available Providers */
528+ diagnostics .append ("All Available Providers:\n " );
529+ Provider [] allProviders = Security .getProviders ();
530+ for (Provider p : allProviders ) {
531+ diagnostics .append (" " ).append (p .getName ())
532+ .append (" v" ).append (p .getVersion ())
533+ .append (" - " ).append (p .getInfo ()).append ("\n " );
534+ }
535+
536+ System .err .println (diagnostics .toString ());
537+
371538 fail ("Signature verification failed when generating with " +
372539 "wolfJCE and verifying with system default JCE " +
373- "provider" );
540+ "provider. See diagnostics above for " +
541+ "reproduction details." );
374542 }
375543 }
376544 }
0 commit comments