Start to implement certificate parsing.
Cleanup comments, fix leaks, etc.
Remove old comment.
Merge branch 'master' into authenticode

Conflicts:
	libyara/modules/pe.c
Fix serial handling.

Rather than "continue" the loop if there is no serial length. This allows
us to get other things later in the loop.
Merge branch 'master' into authenticode
Merge branch 'null_ptr_fix' into authenticode
Merge branch 'null_ptr_fix' into authenticode
Properly calculate the next certificate entry.

There is a lot of confusion around this. The specification says it must be
aligned to an 8 byte boundary and the length field does not include the
structure itself. Most binaries adhere to this but I've seen some for which
the length includes the structure and the padding.

There needs to be more investigation on the proper way to handle the (rare)
case of a file with multiple signatures.
Merge branch 'master' into authenticode
Fix some bugs.

Make sure cert_bio is NULL. If we have to break early it won't be
erroneously freed.

Fix up the pointer math walking the certificate attribute table.

Make sure the certificate length fits in what we have to work with.

Only handle PKCS#7 and Revision 2 for now.

Fix a memory leak by freeing cert_bio at the end of each loop.
Fix length check. The docs are confusing.

Also, set cert_bio to NULL after free.
Add extra comment explaining why this check most likely fails.
Make length check bounded to directory.
Cleanup bounds checks and comments.

Make sure that the structure fits in both PE and directory. No need
to do the check inside the while loop now that it's moved. Cleanup
comments to be more descriptive.
IMAGE_SECURITY_DESCRIPTOR -> WIN_CERTIFICATE

Rename the horribly named IMAGE_SECURITY_DESCRIPTOR to the more appropriately
named WIN_CERTIFICATE.
Fix comparisons.
Remove unnecessary code.

If we ever hit this point cert_bio is already NULL.
Merge branch 'master' into authenticode
Implement signature as an array.

Store the length of the array in a variable. This makes the following rule
run (though not work):

rule authenticode_array_test {
  condition:
    for any i in (0..pe.signature_length):
      (pe.signature[i].issuer == "/CN=Fedora Secure Boot CA")
}

When run against shim-0.2-3.2.fc18.x86_64.efi it does not find the second
certificate. Still need to debug why.