Index: libabac/abac.c
===================================================================
--- libabac/abac.c	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac.c	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -125,4 +125,22 @@
 }
 
+
+/**
+ * Load an ID cert and privkey from chunks.
+ */
+int abac_context_load_id_privkey_chunk(abac_context_t *ctx, abac_chunk_t cert, abac_chunk_t privkey) {
+    assert(ctx != NULL);
+    abac_id_credential_t *id_cert=NULL;
+    chunk_t cert_chunk = { cert.ptr, cert.len };
+    chunk_t privkey_chunk = { privkey.ptr, privkey.len };
+    int ret=abac_verifier_load_id_privkey_chunk(cert_chunk, privkey_chunk, &id_cert);
+
+    if(id_cert) {
+        int add_ret = abac_pl_add_type_credential(ctx->pl, id_cert);
+    }
+    return ret;
+}
+
+
 /**
  * Load an attribute cert from an abac_attribute_t.
@@ -178,5 +196,5 @@
         add_ret = abac_pl_add_credential(ctx->pl, cred);
         assert(add_ret != ABAC_PL_CRED_INVALID);
-        abac_credential_free(cred);
+        /* abac_credential_free(cred); */
     }
 
Index: libabac/abac.h
===================================================================
--- libabac/abac.h	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac.h	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -71,4 +71,5 @@
 int abac_id_write_privkey(abac_id_t *id, FILE *out);
 abac_chunk_t abac_id_cert_chunk(abac_id_t *id);
+abac_chunk_t abac_id_privkey_chunk(abac_id_t *id);
 char *abac_id_string(abac_id_t *id);
 int abac_id_load_privkey_file(abac_id_t *id, char *filename);
@@ -187,4 +188,5 @@
 
 int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert);
+int abac_context_load_id_privkey_chunk(abac_context_t *ctx, abac_chunk_t cert, abac_chunk_t privkey);
 int abac_context_load_attribute_file(abac_context_t *ctx, char *filename);
 int abac_context_load_id(abac_context_t *ptr, abac_id_t *id);
Index: libabac/abac.hh
===================================================================
--- libabac/abac.hh	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac.hh	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -771,7 +771,14 @@
      can be passed to libabac's Context::load_id_chunk() 
      (C:abac_id_cert_chunk)
+f  abac_chunk_t id_privkey_chunk()
+     returns a PEM-encoded binary representation of the private key 
+     associated with this ID.
+     can be passed to libabac's Context::load_id_chunks() 
+     (C:abac_id_privkey_chunk)
 ***/
             abac_chunk_t id_cert_chunk()
             { return abac_id_cert_chunk(m_id); }
+            abac_chunk_t id_privkey_chunk()
+            { return abac_id_privkey_chunk(m_id); }
 /***
 f  char *string()
@@ -1075,4 +1082,7 @@
      load id cert from a chunk structure
      (C:abac_context_load_id_chunk)
+f  int load_id_chunks(abac_chunk_t, abac_chunk_t) 
+     load id privkey from a chunk structure
+     (C:abac_context_load_id_privkey_chunk)
      returns:
        ABAC_CERT_SUCCESS   successfully loaded
@@ -1088,4 +1098,6 @@
             int load_id_chunk(abac_chunk_t cert) 
             { return abac_context_load_id_chunk(m_ctx, cert); }
+            int load_id_chunks(abac_chunk_t cert, abac_chunk_t privkey) 
+            { return abac_context_load_id_privkey_chunk(m_ctx, cert, privkey); }
 
 /***
Index: libabac/abac_id.c
===================================================================
--- libabac/abac_id.c	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac_id.c	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -398,4 +398,17 @@
 
 /**
+ * Get a PEM-encoded chunk representing the private key 
+ */
+abac_chunk_t abac_id_privkey_chunk(abac_id_t *id) {
+    assert(id->cert);
+
+    chunk_t encoding = chunk_empty;
+    int rc= id->key->get_encoding(id->key, PRIVKEY_PEM, &encoding);
+    abac_chunk_t ret = { encoding.ptr, encoding.len };
+
+    return ret;
+}
+
+/**
  * Copy an abac ID. Actually just increases its reference count.
  */
@@ -428,6 +441,4 @@
  */
 int abac_id_load_privkey_file(abac_id_t *id, char *filename) {
-    struct cb_opts c_opts = { 1, 0, 3, "Key password:" };
-
     assert(id != NULL);
 
@@ -436,7 +447,4 @@
         CRED_PRIVATE_KEY, KEY_RSA,
         BUILD_FROM_FILE, filename,
-/*NOT in 4.6.4 Ask for password if the key's encrypted 
-        BUILD_PASSPHRASE_CALLBACK, _passphrase_callback, &c_opts,
-*/
         BUILD_END
     );
@@ -449,6 +457,4 @@
 
 int abac_id_load_privkey_chunk(abac_id_t *id, chunk_t chunk) {
-    struct cb_opts c_opts = { 1, 0, 3, "Key password:" };
-
     assert(id != NULL);
 
@@ -457,7 +463,4 @@
         CRED_PRIVATE_KEY, KEY_RSA,
         BUILD_BLOB_PEM, chunk,
-/* NOT in 4.6.4 Ask for password if the key's encrypted 
-        BUILD_PASSPHRASE_CALLBACK, _passphrase_callback, &c_opts,
-*/
         BUILD_END
     );
Index: libabac/abac_pl_gen.c
===================================================================
--- libabac/abac_pl_gen.c	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac_pl_gen.c	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -37,4 +37,9 @@
 
 extern char* abac_yyfptr_encoded;
+
+void generate_pl_set_abac_yyfptr_encoded(char *string)
+{
+   abac_yyfptr_encoded=abac_xstrdup(string);
+}
 
 char *generate_pl_type_clause(char *principalname, int type);
Index: libabac/abac_pl_yap.c
===================================================================
--- libabac/abac_pl_yap.c	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac_pl_yap.c	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -213,5 +213,5 @@
                  if(i) cnt++;
                  } else {
-                 printf("BAD BAD BAD\n");
+                 printf("BAD BAD\n");
              }
              sptr=cptr;
Index: libabac/abac_verifier.c
===================================================================
--- libabac/abac_verifier.c	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac_verifier.c	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -38,4 +38,5 @@
 extern char *generate_pl_type_clause(char *, int);
 extern abac_list_t *generate_pl_clauses(abac_aspect_t *, abac_aspect_t *);
+extern void generate_pl_set_abac_yyfptr_encoded(char *string);
 
 extern void abac_print_aspect_string_with_condition(abac_aspect_t *role, FILE*);
@@ -459,5 +460,7 @@
 }
 /**
- * Load an ID cert from a chunk.
+ * Load an ID cert from a chunk, Note, this only loads the id cert part
+ * and so it is not suitable for creating an attribute credential with. 
+ * Only a complete id cert + privkey could create attribute credential.
  */
 int abac_verifier_load_id_chunk(chunk_t chunk, abac_id_credential_t **id_cred_ret) {
@@ -474,4 +477,31 @@
     return _load_id(&id, cert,id_cred_ret);
 }
+
+/**
+ * Load an ID cert from a cert chunk and a privkey chunk,
+ * this complete id cert + privkey could create attribute credential.
+ */
+int abac_verifier_load_id_privkey_chunk(chunk_t chunk, chunk_t privkey_chunk,
+abac_id_credential_t **id_cred_ret) {
+
+    abac_id_t *id=NULL;
+    // load the cert
+    certificate_t *cert = lib->creds->create(
+        lib->creds, CRED_CERTIFICATE, CERT_X509,
+        BUILD_BLOB_ASN1_DER, chunk,
+        BUILD_X509_FLAG, X509_AA, // attribute authority, dumb
+        BUILD_END
+    );
+    if (cert == NULL)
+        return ABAC_CERT_INVALID;
+
+    int rc=_load_id(&id, cert,id_cred_ret);
+    if(rc == ABAC_CERT_SUCCESS) {
+        rc=abac_id_load_privkey_chunk(id, privkey_chunk);
+    }
+
+    return rc;
+}
+
 
 abac_id_t *abac_verifier_load_issuer(char *filename, char *keyfilename)
@@ -737,4 +767,9 @@
     assert(attr_hashkeyid_list);
     abac_list_add(attr_hashkeyid_list, abac_xstrdup(cred->hashkeyid));
+
+    if(debug)
+        printf("-->adding into attr_creds 2, (%s)..cnt(%d)\n",
+                                   cred->hashkeyid, HASH_COUNT(attr_creds));
+
     return ABAC_CERT_SUCCESS;
 
@@ -815,8 +850,12 @@
     preprocess_pl_tail(tail);
 
-/* XXX collect up type clauses, constraint clauses and
+/* setup the encoded attribute string */
+    char *encoded_attr_string=get_cred_encoding(ptr);
+    generate_pl_set_abac_yyfptr_encoded(encoded_attr_string);
+/* collect up type clauses, constraint clauses and
    generate rule clauses */
     abac_list_t *clauses=generate_pl_clauses(head,tail);
-    char *encoded_attr_string=get_cred_encoding(ptr);
+
+    abac_print_clauses(clauses,NULL);
 
     abac_credential_t *cred = abac_xmalloc(sizeof(abac_credential_t));
@@ -831,4 +870,8 @@
     assert(attr_hashkeyid_list);
     abac_list_add(attr_hashkeyid_list, abac_xstrdup(cred->hashkeyid));
+
+    if(debug)
+        printf("-->adding into attr_creds, (%s)..cnt(%d)\n",
+                                   cred->hashkeyid, HASH_COUNT(attr_creds));
     return ABAC_CERT_SUCCESS;
 }
@@ -862,4 +905,5 @@
     if (cert == NULL)
         return ABAC_CERT_INVALID;
+
     return _load_attribute_cert(cert, cred);
 }
@@ -920,4 +964,5 @@
         printf("abac_credential_lookup: looking for (%s)\n", cred_string);
     abac_credential_t *attr_cred;
+
     HASH_FIND_STR(attr_creds, cred_string, attr_cred);
     if (attr_cred == NULL) {
Index: libabac/abac_verifier.h
===================================================================
--- libabac/abac_verifier.h	(revision 4b46680a90e4903fb5b827f0c0ea41e0a98c03d4)
+++ libabac/abac_verifier.h	(revision 9b43fc3d618a238405947779470f1a092ba98648)
@@ -14,4 +14,5 @@
 int abac_verifier_load_id_file(char *filename, char*, abac_id_credential_t **id_cert);
 int abac_verifier_load_id_chunk(chunk_t chunk, abac_id_credential_t **id_cert);
+int abac_verifier_load_id_privkey_chunk(chunk_t chunk, chunk_t, abac_id_credential_t **id_cert);
 int abac_verifier_load_attribute_cert_attribute(abac_attribute_t *, abac_credential_t **cred);
 int abac_verifier_load_attribute_cert_file(char *filename, abac_credential_t **cred);
