Skip to content

Instantly share code, notes, and snippets.

@as1an
as1an / PKIXUtil.java
Last active August 1, 2025 14:24
Построение иерархии сертификатов НУЦ\КУЦ и проверка на действительность по CRL или OCSP
package kz.gov.pki.provider.utils;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.cert.CertPathBuilder;
import java.security.cert.CertPathBuilderException;
import java.security.cert.CertPathBuilderResult;
import java.security.cert.CertStore;
import java.security.cert.CollectionCertStoreParameters;
package kz.gov.pki.kalkan.pkix.checker;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.cert.CertPathBuilder;
package kz.exploit.hape
import java.net.URL
import java.io.File
import java.io.BufferedWriter
import java.io.OutputStreamWriter
import java.net.HttpURLConnection
fun main(args: Array<String>) {
@as1an
as1an / SimpleManualWSSE.java
Created September 23, 2020 08:15
A messy example of the manual signing and verifying of the soap message using XPath. It is preferred to use wss4j+jsr105 (https://github.com/pkigovkz/SpringWSSample).
package kz.sample.test;
import kz.gov.pki.kalkan.asn1.pkcs.PKCSObjectIdentifiers;
import kz.gov.pki.kalkan.jce.provider.KalkanProvider;
import kz.gov.pki.kalkan.xmldsig.KncaXS;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.message.WSSecHeader;
import org.apache.ws.security.message.token.SecurityTokenReference;
import org.apache.xml.security.c14n.Canonicalizer;
import org.apache.xml.security.encryption.XMLCipherParameters;
@as1an
as1an / CSRUtil.java
Created November 25, 2020 19:28
Пример генерации ключевых пар и формирования запроса PKCS#10
package kz.gov.pki.live;
import java.io.StringWriter;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Security;
import java.security.spec.ECGenParameterSpec;
import kz.gov.pki.kalkan.asn1.ASN1Set;
@as1an
as1an / SimpleCms.java
Created June 23, 2021 12:48
Basic CMS generation and validation
package kz.gov.pki.provider.utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
### Keybase proof
I hereby claim:
* I am as1an on github.
* I am as1an (https://keybase.io/as1an) on keybase.
* I have a public key ASC_DEO1yJeSOBwWI7qFhrhL6DVgBPGioPbnVwQyvMEVAwo
To claim this, I am signing this object:
public class Providers {
public static void main(String[] args) {
java.util.Arrays.asList(java.security.Security.getProviders()).stream().forEach(System.out::println);
}
}
@as1an
as1an / cms_sign.m
Last active July 18, 2022 19:56
CMS signing example with <openssl/cms.h>
BIO *in = NULL, *out = NULL;
CMS_ContentInfo *cms = NULL;
CMS_SignerInfo *si = NULL;
unsigned char *cms_pem = NULL;
int cms_flags = CMS_NOSMIMECAP | CMS_BINARY | CMS_PARTIAL | CMS_STREAM;
int cms_pem_len = 0;
NSString *nsstring = @"c2FtcGxl";
const unsigned char *cstring = (const unsigned char *) [nsstring UTF8String];
@as1an
as1an / some_cert_info.c
Created August 15, 2022 08:33
Example of getting some information using Kalkancrypt (OpenSSL 1.0.x)
BIO *not_before_bio = BIO_new(BIO_s_mem());
ASN1_TIME_print(not_before_bio, X509_get_notBefore(cert)); // format MMM DD HH:MM:SS YYYY [GMT]
// ASN1_STRING_print_ex(not_before_bio, X509_get_notAfter(cert), ASN1_STRFLGS_UTF8_CONVERT); // UTC format YYMMDDHHMMSSZ
int not_before_len = BIO_number_written(not_before_bio);
unsigned char *not_before = (unsigned char *)calloc(not_before_len, sizeof(unsigned char));
BIO_read(not_before_bio, not_before, not_before_len);
NSLog(@"not before: %s", not_before);
BIO_free(not_before_bio);