# AS2 task

An AS2 task sends the files on the list to a trading partner by AS2: signed, encrypted, and with a receipt from the partner that says the file arrived as it was sent. AS2 is the way retailers, logistics firms and banks exchange EDI documents.

This page is about the task. The whole of AS2 on the server, receiving, partners, certificates and receipts, is in [AS2](AS2.md); the job around this task is in [Sending](AS2-Sending.md).

## What you need from the partner

| | |
|---|---|
| their **AS2 name** and yours | each side has an identifier, agreed between you |
| their **address** | the URL their AS2 server listens on |
| their **certificate** | to encrypt for them and to check their receipts |
| the algorithms | for signing and for encrypting |
| the kind of receipt | at once, or later (asynchronous) |

And they need your certificate.

## Fields

### Options

| Field | What it does | On a new task |
|---|---|---|
| **From Partner** | your AS2 name | |
| **To Partner** | the partner's AS2 name | |
| **Recipient URL** | the partner's address. "Only http and https urls allowed." | |
| **Subject** | the subject line of the message | `Testing` |
| **From Email** | a mail address for the message's From line | |
| **Sign Message** | **None**, **Md5**, **sha1**, **sha-256** | sha-256 |
| **Encrypt Message** | **None**, **3des**, **aes_128**, **aes_192**, **aes_256**, **rc4_40**, **rc4_56**, **rc4_128** | aes_256 |
| **Use compression** | the file is compressed before it is signed | off |
| **Async MDN** | the receipt is not awaited in the same connection; the partner sends it later to the **Response URL** | off |
| **Response URL** | where the partner sends a later receipt: this server's AS2 address | empty: fill it in when **Async MDN** is on |
| **MDN Wait Timeout** | seconds to wait for a later receipt before the task fails: "Timeout reached while waiting for MDN responses." | 600 |
| **MIC Algorithm** | the checksum the receipt is asked to use. "It is very unusual to change this value at all." | `optional, sha-256, sha1, md5` |
| **Delay between sends** | seconds between two files | 0 |
| **Accept Any Cert** | the partner's HTTPS certificate is not checked. For a first test only. | off |
| **Route connection through DMZ when possible** | the message is sent from a DMZ server | |

A new task starts with **sha-256** and **aes_256**. Choose another only when the partner cannot do these. Md5, sha1, 3des and the rc4 kinds are there for old partners; they are not safe any more. A task saved before keeps what it has.

### Signing

Your own key, which signs what you send:

| Field | What it does |
|---|---|
| **Keystore Path** | the file that holds your private key and certificate. **Browse**. |
| **Keystore Format** | **JKS** or **PKCS12** |
| **Keystore Password**, **Key Password** | |
| **Key name (alias)** | which key of the store |
| **Keystore Utility** | opens the tool for looking into and making key stores |

### Encryption

The partner's certificate, for which the message is encrypted:

| Field | What it does |
|---|---|
| **Keystore Path**, **Keystore Format**, **Keystore Password** | the store that holds it |
| **Key name (alias)** | the partner's certificate in it |
| **Keystore Utility** | |

### Extra headers

Headers of your own can be added behind the address, after a `#`: `https://as2.partner.example/receive#Content-Type=application/edifact&X-Route=orders`.

## The receipt

The partner answers each message with a receipt, the MDN. It says that the message was received and, by a checksum, that it arrived unchanged. The task checks it.

| Receipt | The task |
|---|---|
| at once (synchronous) | has it when the send ends |
| later (asynchronous) | waits for it, up to **MDN Wait Timeout** |
| says the message was refused, or never comes | fails |

Each sent file gets `{mdn_result}`: what the receipt said. The receipts are also put on the list as items, so that a job can keep them: partners and auditors ask for them.

## What it hands on

The items it was given, with their receipts.

## Things to know

- **One file, one message.** Each file on the list is its own AS2 message with its own receipt.
- **Trying it.** Most partners have a test address. Send a small file there first, with **Accept Any Cert** off, and compare the checksum in the receipt.
- **When it fails**, the log has the partner's answer. The usual causes: the AS2 names do not match what the partner has set up, to the letter and the capital; the partner does not have your current certificate; an algorithm they do not accept.
- **Certificates run out.** Both yours and the partner's. Note the dates; an AS2 link that worked for two years and stops one morning is nearly always that.
- **Limited admins** need the right to use this task and the partner's host: see [Who may see, change and run a job](Jobs-Access.md).
