com.ibm.as400.access

Class AS400CertificateUtil

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    AS400CertificateUserProfileUtil, AS400CertificateVldlUtil


    public abstract class AS400CertificateUtil
    extends Object
    implements Serializable
    Provides the methods common to AS400CertificateVldlUtil and AS400CertificateUserProfileUtil. The following example demonstrates the use of AS400CertificateUtil, AS400CertificateVldlUtil, and AS400CertificateUserProfileUtil. It copies an arbitrary number of X.509 certificates from an IBM i user profile to an IBM i validation list (vldl) object. The user profile certificates are first placed into a user space and then added to the validation list:
          // Get certificates from the local system
        AS400 as400 = new AS400();
    
    // Local variables AS400Certificate as400certificate; AS400Certificate[] certs;
    Vector certVector = new Vector(); byte[] handle; int numberCerts; String userName;

    try {
    AS400CertificateUserProfileUtil usrprf = new AS400CertificateUserProfileUtil(as400, "/QSYS.LIB/MYNAME.USRPRF");
    AS400CertificateVldlUtil vldl = new AS400CertificateVldlUtil(as400, "/QSYS.LIB/MYLIB.LIB/TEST.VLDL");
    AS400CertificateAttribute[] certAttribute = new AS400CertificateAttribute[2];

    // Copy certificates that belong to both "US" and "myname". certAttribute[0] = new AS400CertificateAttribute(AS400CertificateAttribute.SUBJECT_COUNTRY, "US");
    certAttribute[1] = new AS400CertificateAttribute(AS400CertificateAttribute.SUBJECT_COMMON_NAME, "myname");

    // Copy matching certificates from the user profile to user space, MYSPACE. numberCerts = usrprf.listCertificates(certAttribute, "/QSYS.LIB/MYLIB.LIB/MYSPACE.USRSPC");
    System.out.println("Number of certificates found => " + numberCerts);

    // Start reading certificates from the user space into AS400Certificate[]. // All complete certificates in the 8 Kbyte buffer will be returned. certs = usrprf.getCertificates("/QSYS.LIB/MYLIB.LIB/MYSPACE.USRSPC", 0, 8);
    // Continue to read the entire user space using 8 Kbyte buffer while (null != certs) { // Gather certificates in a vector for (int i = 0; i < certs.length; ++i) { certVector.addElement(certs[i]); }
    certs = usrprf.getNextCertificates(8); }

    // Add all the certificates to validation list object for (int i = 0; i < certVector.size(); ++i) { as400certificate = (AS400Certificate)certVector.elementAt(i); vldl.addCertificate(as400certificate.getEncoded()); }
    // Delete first certificate added to vldl using its handle as400certificate = (AS400Certificate)certVector.elementAt(0); handle = usrprf.getCertificateHandle(as400certificate.getEncoded()); vldl.deleteCertificateByHandle(handle);
    // Delete 2nd certificate added to vldl using entire ASN.1 certificate as400certificate = (AS400Certificate)certVector.elementAt(1); vldl.deleteCertificate(as400certificate.getEncoded());
    // Display user profile name associated with the 1st certificate userName = usrprf.findCertificateUserByHandle(handle);
    System.out.println("User profile name => " + userName); }
    catch (Exception e) { System.out.println(e.toString()); }
    See Also:
    AS400CertificateVldlUtil, AS400CertificateUserProfileUtil, Serialized Form