# Ccall help

**URL:** https://discourse.julialang.org/t/ccall-help/34785
**Category:** General Usage
**Tags:** ccall
**Created:** [February 18, 2020, 3:23am UTC](https://discourse.julialang.org/t/ccall-help/34785 "2020-02-18T03:23:34Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [February 18, 2020, 3:23am UTC](https://discourse.julialang.org/t/ccall-help/34785/1 "2020-02-18T03:23:35Z")

</div>

Hi all,

I’m trying to get OnlinePackage to be able to post a package on github, but also set up the necessary SSH keys to get documenter building. I had it working on travis, but now I’m trying to get it work with github actions.

The new wrinkle is the github actions API requires “secrets” be uploaded via libsodium. Julia has a Sodium.jl wrapper library but it is very out of date…

Anyway, I used binary builder to build libsodium so you can download it now `using libsodium_jll`. Now I’m trying to call its functions via ccall. I’ve never used ccall before, so I’m not sure if I’m doing it right…

The relevant part of the function is here:

```julia
 sodium_key_id = json_string(talk_to(HTTP.get, github_remote,
        "/repos/$username/$repo_name/actions/secrets/public-key"
    ))

    sodium_key = base64decode(sodium_key_id["key"])
    raw_encoded = Vector{UInt8}(undef,
        length(private_key) +
        ccall((:crypto_box_sealbytes, libsodium), Cint, ())
    )
    error_code = ccall(
        (:crypto_box_seal, libsodium),
        Int32,
        (Ptr{UInt8}, Cstring, Cint, Ptr{UInt8}),
        raw_encoded, private_key, length(private_key), sodium_key
    )
    if error_code != 0
        error("Error using libsodium.crypto_box_seal")
    end
    talk_to(
        HTTP.put, github_remote, "/repos/$username/$repo_name/actions/secrets/$key_name",
        encrypted_value = base64encode(unsafe_string(pointer(raw_encoded), length(raw_encoded))),
        key_id = sodium_key_id["key_id"]
    )

```

Unfortunately, it doesn’t seem to be enough to get documenter building. I’m getting the error:

```julia
Load key "/home/runner/work/JuliennedArrays.jl/JuliennedArrays.jl/docs/.documenter": invalid format
git@github.com: Permission denied (publickey).

```

The full function is on the github repo here:

> **[GitHub - bramtayl/OnlinePackage.jl: Create packages quickly](https://github.com/bramtayl/OnlinePackage.jl/)**
>
> Create packages quickly. Contribute to bramtayl/OnlinePackage.jl development by creating an account on GitHub.

You can see a failing documenter build here:

[https://github.com/bramtayl/JuliennedArrays.jl/runs/451494597](https://github.com/bramtayl/JuliennedArrays.jl/runs/451494597)

The github secrets api documentation is here:

> **[GitHub Actions Secrets - GitHub Docs](https://docs.github.com/en/rest/actions/secrets)**
>
> Use the REST API to interact with secrets in GitHub Actions.

and the libsodium sealed box documentation is here:

> **[Sealed boxes](https://libsodium.gitbook.io/doc/public-key_cryptography/sealed_boxes)**

Can anyone give some advice about what to do next?

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [February 18, 2020, 4:40am UTC](https://discourse.julialang.org/t/ccall-help/34785/2 "2020-02-18T04:40:11Z")

</div>

X-ref: [Macro help · Issue #255 · JuliaInterop/Clang.jl · GitHub](https://github.com/JuliaInterop/Clang.jl/issues/255#issuecomment-587272572)

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [February 18, 2020, 5:36am UTC](https://discourse.julialang.org/t/ccall-help/34785/3 "2020-02-18T05:36:21Z")

</div>

the C language function signature:

```julia
int
crypto_box_seal( 
    unsigned char *c, const unsigned char *m,
    unsigned long long mlen, const unsigned char *pk)

```

here is the example from the doc “sealed\_boxes”

```julia
#define MESSAGE (const unsigned char *) "Message"
#define MESSAGE_LEN 7
#define CIPHERTEXT_LEN (crypto_box_SEALBYTES + MESSAGE_LEN)

/* Recipient creates a long-term key pair */
unsigned char recipient_pk[crypto_box_PUBLICKEYBYTES];
unsigned char recipient_sk[crypto_box_SECRETKEYBYTES];

crypto_box_keypair(recipient_pk, recipient_sk);

/* Anonymous sender encrypts a message using an ephemeral key pair
 * and the recipient's public key */
unsigned char ciphertext[CIPHERTEXT_LEN];

crypto_box_seal(ciphertext, MESSAGE, MESSAGE_LEN, recipient_pk);

```

---

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [February 18, 2020, 1:32pm UTC](https://discourse.julialang.org/t/ccall-help/34785/4 "2020-02-18T13:32:55Z")

</div>

Here’s a MWE:

```julia
using Base64
using libsodium_jll

ssh_private_key = base64encode('A' ^ 3512)
downloaded_key = base64decode('A' ^ 44)
raw_encoded = Vector{UInt8}(undef,
    length(ssh_private_key) +
    ccall((:crypto_box_sealbytes, libsodium), Cint, ())
)
init_error_code = ccall((:sodium_init, libsodium), Int32, ())
seal_error_code = ccall(
    (:crypto_box_seal, libsodium),
    Int32,
    (Ptr{UInt8}, Cstring, Cint, Ptr{UInt8}),
    raw_encoded, private_key, length(private_key), sodium_key
)
base64encode(raw_encoded)

```

Unfortunately, I think the only way to validate whether the encoding actually worked is to download and checkout OnlinePackage and try to use it on one of your own packages with docs hosted on githubpages.

---

<div class="post-metadata">

### Author: ![christopher-dG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher-dg/32/7387_2.png) [@christopher-dG](https://discourse.julialang.org/u/christopher-dG)
#### Post date: [February 18, 2020, 3:05pm UTC](https://discourse.julialang.org/t/ccall-help/34785/5 "2020-02-18T15:05:36Z")

</div>

I’m doing the same GitHub secrets stuff, you may be interested in [SodiumSeal.jl](https://github.com/christopher-dG/SodiumSeal.jl) which has a nice Julian API and is 1.0-compatible.

---

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [February 18, 2020, 4:49pm UTC](https://discourse.julialang.org/t/ccall-help/34785/6 "2020-02-18T16:49:35Z")

</div>

@christopher-dG you might want to look at [Macro help · Issue #255 · JuliaInterop/Clang.jl · GitHub](https://github.com/JuliaInterop/Clang.jl/issues/255)

@Gnimuc has cooked up [GitHub - Gnimuc/Sodium.jl: Julia wrapper for libsodium](https://github.com/Gnimuc/Sodium.jl)

I figured out the problem with my code. It wasn’t to do with ccall. Instead it was the chomp in the private key line: formerly was necessary to remove the newline at the end, but now I guess the newline is required?

---

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [February 18, 2020, 5:02pm UTC](https://discourse.julialang.org/t/ccall-help/34785/7 "2020-02-18T17:02:59Z")

</div>

@christopher-dG OnlinePackage is now updated to work with github actions. Let me know if/when you want to move it into PkgTemplates and I can deprecate OnlinePackage

---

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [February 18, 2020, 5:08pm UTC](https://discourse.julialang.org/t/ccall-help/34785/8 "2020-02-18T17:08:20Z")

</div>

Might be good to coordinate with @mortenpi who can update the hosting docs on Documenter to point users to the best way to programmatically submit SSH keys

---

<div class="post-metadata">

### Author: ![christopher-dG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher-dg/32/7387_2.png) [@christopher-dG](https://discourse.julialang.org/u/christopher-dG)
#### Post date: [February 19, 2020, 1:30am UTC](https://discourse.julialang.org/t/ccall-help/34785/9 "2020-02-19T01:30:37Z")

</div>

> [@bramtayl](#):
>
> I figured out the problem with my code. It wasn’t to do with ccall. Instead it was the chomp in the private key line: formerly was necessary to remove the newline at the end, but now I guess the newline is required?

Yeah that’s an SSH thing, [I ran into that too](https://github.com/JuliaRegistries/TagBot/blob/032107afd0d5e5ca3205624eb93bba531a61f452/tagbot/repo.py#L204).
